Please check what is the diff and don't commit such changes ! Having commit notifications is useless if we mix functional changes with code formatting like this.
Martin Grigorov Wicket Training and Consulting On Tue, Jan 14, 2014 at 6:00 PM, <[email protected]> wrote: > Updated Branches: > refs/heads/wicket-6.x f7a616bdb -> c13084b88 > > > WICKET-5466 watch out for null component; break early from method > > Project: http://git-wip-us.apache.org/repos/asf/wicket/repo > Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/c13084b8 > Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/c13084b8 > Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/c13084b8 > > Branch: refs/heads/wicket-6.x > Commit: c13084b881f8924d9fb9ec8847e8e9dab9e118a7 > Parents: f7a616b > Author: svenmeier <[email protected]> > Authored: Tue Jan 14 16:59:54 2014 +0100 > Committer: svenmeier <[email protected]> > Committed: Tue Jan 14 16:59:54 2014 +0100 > > ---------------------------------------------------------------------- > .../ListenerInterfaceRequestHandler.java | 91 ++++++++++---------- > .../ListenerInterfaceRequestHandlerTest.java | 31 ++++++- > 2 files changed, 77 insertions(+), 45 deletions(-) > ---------------------------------------------------------------------- > > > > http://git-wip-us.apache.org/repos/asf/wicket/blob/c13084b8/wicket-core/src/main/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandler.java > ---------------------------------------------------------------------- > diff --git > a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandler.java > b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandler.java > index 46c631f..bea6e1f 100644 > --- > a/wicket-core/src/main/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandler.java > +++ > b/wicket-core/src/main/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandler.java > @@ -172,65 +172,68 @@ public class ListenerInterfaceRequestHandler > component = null; > } > > - if ((component == null && freshPage) || > - (component != null && getComponent().getPage() == > page)) > + > + if ((component == null && !freshPage) || (component != > null && component.getPage() != page)) > { > - if (page instanceof Page) > - { > - // initialize the page to be able to check > whether it is stateless > - ((Page)page).internalInitialize(); > - } > - final boolean isStateless = page.isPageStateless(); > + throw new WicketRuntimeException("Component '" + > getComponentPath() > + + "' has been removed from page."); > + } > + > + if (page instanceof Page) > + { > + // initialize the page to be able to check whether > it is stateless > + ((Page)page).internalInitialize(); > + } > + final boolean isStateless = page.isPageStateless(); > > - RedirectPolicy policy = isStateless ? > RedirectPolicy.NEVER_REDIRECT > + RedirectPolicy policy = isStateless > + ? RedirectPolicy.NEVER_REDIRECT > : RedirectPolicy.AUTO_REDIRECT; > - final IPageProvider pageProvider = new > PageProvider(page); > + final IPageProvider pageProvider = new PageProvider(page); > > - if (freshPage && (isStateless == false || > component == null)) > + if (freshPage && (isStateless == false || component == > null)) > + { > + // A listener interface is invoked on an expired > page. > + > + // If the page is stateful then we cannot assume > that the listener > + // interface is > + // invoked on its initial state (right after page > initialization) > + // and that its > + // component and/or behavior will be available. > That's why the > + // listener interface > + // should be ignored and the best we can do is to > re-paint the newly > + // constructed > + // page. > + > + if (LOG.isDebugEnabled()) > { > - // A listener interface is invoked on an > expired page. > - > - // If the page is stateful then we cannot > assume that the listener interface is > - // invoked on its initial state (right > after page initialization) and that its > - // component and/or behavior will be > available. That's why the listener interface > - // should be ignored and the best we can > do is to re-paint the newly constructed > - // page. > - > - if (LOG.isDebugEnabled()) > - { > - LOG.debug( > + LOG.debug( > "A ListenerInterface '{}' > assigned to '{}' is executed on an expired stateful page. " > - + "Scheduling > re-create of the page and ignoring the listener interface...", > + + > "Scheduling re-create of the page and ignoring the listener interface...", > listenerInterface, > getComponentPath()); > - } > - > - if (isAjax) > - { > - policy = > RedirectPolicy.ALWAYS_REDIRECT; > - } > - > - > requestCycle.scheduleRequestHandlerAfterCurrent(new > RenderPageRequestHandler( > - pageProvider, policy)); > - return; > } > > - if (isAjax == false && > listenerInterface.isRenderPageAfterInvocation()) > + if (isAjax) > { > - // schedule page render after current > request handler is done. this can be > - // overridden during invocation of listener > - // method (i.e. by calling > RequestCycle#setResponsePage) > - > requestCycle.scheduleRequestHandlerAfterCurrent(new > RenderPageRequestHandler( > - pageProvider, policy)); > + policy = RedirectPolicy.ALWAYS_REDIRECT; > } > > - invokeListener(); > - > + > requestCycle.scheduleRequestHandlerAfterCurrent(new > RenderPageRequestHandler( > + pageProvider, policy)); > + return; > } > - else > + > + if (isAjax == false && > listenerInterface.isRenderPageAfterInvocation()) > { > - throw new WicketRuntimeException("Component " + > getComponent() + > - " has been removed from page."); > + // schedule page render after current request > handler is done. this > + // can be > + // overridden during invocation of listener > + // method (i.e. by calling > RequestCycle#setResponsePage) > + > requestCycle.scheduleRequestHandlerAfterCurrent(new > RenderPageRequestHandler( > + pageProvider, policy)); > } > + > + invokeListener(); > } > > private void invokeListener() > > > http://git-wip-us.apache.org/repos/asf/wicket/blob/c13084b8/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandlerTest.java > ---------------------------------------------------------------------- > diff --git > a/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandlerTest.java > b/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandlerTest.java > index 9cd6905..30416c8 100644 > --- > a/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandlerTest.java > +++ > b/wicket-core/src/test/java/org/apache/wicket/core/request/handler/ListenerInterfaceRequestHandlerTest.java > @@ -23,13 +23,16 @@ import org.apache.wicket.MarkupContainer; > import org.apache.wicket.Page; > import org.apache.wicket.RequestListenerInterface; > import org.apache.wicket.Session; > +import org.apache.wicket.WicketRuntimeException; > import org.apache.wicket.WicketTestCase; > import org.apache.wicket.ajax.AjaxRequestTarget; > import org.apache.wicket.ajax.markup.html.AjaxLink; > import org.apache.wicket.markup.IMarkupResourceStreamProvider; > import org.apache.wicket.markup.html.WebPage; > +import org.apache.wicket.markup.html.form.IOnChangeListener; > import org.apache.wicket.markup.html.link.ILinkListener; > import org.apache.wicket.request.Url; > +import org.apache.wicket.resource.DummyPage; > import org.apache.wicket.util.resource.IResourceStream; > import org.apache.wicket.util.resource.ResourceStreamNotFoundException; > import org.apache.wicket.util.resource.StringResourceStream; > @@ -42,8 +45,34 @@ public class ListenerInterfaceRequestHandlerTest > extends WicketTestCase > { > > /** > + * WICKET-5466 > + */ > + @Test > + public void removedComponent() > + { > + // non-existing component on fresh page is ignored > + PageAndComponentProvider freshPage = new > PageAndComponentProvider(DummyPage.class, null, > + "foo"); > + new ListenerInterfaceRequestHandler(freshPage, > IOnChangeListener.INTERFACE).respond(tester > + .getRequestCycle()); > + > + // non-existing component on old page fails > + PageAndComponentProvider oldPage = new > PageAndComponentProvider(new DummyPage(), "foo"); > + try > + { > + new ListenerInterfaceRequestHandler(oldPage, > IOnChangeListener.INTERFACE).respond(tester > + .getRequestCycle()); > + fail(); > + } > + catch (WicketRuntimeException ex) > + { > + assertEquals("Component 'foo' has been removed > from page.", ex.getMessage()); > + } > + } > + > + /** > * https://issues.apache.org/jira/browse/WICKET-4116 > - * > + * > * @throws Exception > */ > @Test > >
