Author: mgrigorov
Date: Fri Dec 10 13:31:23 2010
New Revision: 1044355

URL: http://svn.apache.org/viewvc?rev=1044355&view=rev
Log:
Move the page freezing code from ListenerInterfaceRequestHandler to 
RequestListenerInterface
The information about the current request is extracted via 
component.getRequest().

Modified:
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
    
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java?rev=1044355&r1=1044354&r2=1044355&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestListenerInterface.java
 Fri Dec 10 13:31:23 2010
@@ -25,9 +25,11 @@ import java.util.Map;
 
 import org.apache.wicket.authorization.AuthorizationException;
 import org.apache.wicket.behavior.Behavior;
+import org.apache.wicket.request.Request;
 import org.apache.wicket.request.RequestHandlerStack.ReplaceHandlerException;
 import org.apache.wicket.request.component.IRequestableComponent;
 import org.apache.wicket.request.handler.ListenerInvocationNotAllowedException;
+import org.apache.wicket.request.http.WebRequest;
 import org.apache.wicket.util.lang.Classes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -210,30 +212,7 @@ public class RequestListenerInterface
                                "Component rejected interface invocation");
                }
 
-               try
-               {
-                       // Invoke the interface method on the component
-                       method.invoke(component);
-               }
-               catch (InvocationTargetException e)
-               {
-                       // Honor redirect exception contract defined in 
IPageFactory
-                       if (e.getTargetException() instanceof 
ReplaceHandlerException ||
-                               e.getTargetException() instanceof 
AuthorizationException ||
-                               e.getTargetException() instanceof 
WicketRuntimeException)
-                       {
-                               throw (RuntimeException)e.getTargetException();
-                       }
-                       throw new WicketRuntimeException("Method " + 
method.getName() + " of " +
-                               method.getDeclaringClass() + " targeted at 
component " + component +
-                               " threw an exception", e);
-               }
-               catch (Exception e)
-               {
-                       throw new WicketRuntimeException("Method " + 
method.getName() + " of " +
-                               method.getDeclaringClass() + " targeted at 
component " + component +
-                               " threw an exception", e);
-               }
+               internalInvoke(component, component);
        }
 
        /**
@@ -258,10 +237,26 @@ public class RequestListenerInterface
                                "Behavior rejected interface invocation");
                }
 
+               internalInvoke(component, behavior);
+       }
+
+       private void internalInvoke(final Component component, final Object 
target)
+       {
+               Boolean frozen = null;
+
+               // save a reference to the page because the component can be 
removed
+               // during the invocation of the listener and thus lose its 
parent
+               Page page = component.getPage();
+
+               if (isAjax(component))
+               {
+                       // do not increment page id for ajax requests
+                       frozen = page.setFreezePageId(true);
+               }
+
                try
                {
-                       // Invoke the interface method on the component
-                       method.invoke(behavior);
+                       method.invoke(target);
                }
                catch (InvocationTargetException e)
                {
@@ -272,17 +267,39 @@ public class RequestListenerInterface
                                throw (RuntimeException)e.getTargetException();
                        }
                        throw new WicketRuntimeException("Method " + 
method.getName() + " of " +
-                               method.getDeclaringClass() + " targeted at 
behavior " + behavior +
-                               " on component " + component + " threw an 
exception", e);
+                               method.getDeclaringClass() + " targeted at " + 
target + " on component " +
+                               component + " threw an exception", e);
                }
                catch (Exception e)
                {
                        throw new WicketRuntimeException("Method " + 
method.getName() + " of " +
-                               method.getDeclaringClass() + " targeted at 
behavior " + behavior +
-                               " on component " + component + " threw an 
exception", e);
+                               method.getDeclaringClass() + " targeted at " + 
target + " on component " +
+                               component + " threw an exception", e);
+               }
+               finally
+               {
+                       if (frozen != null)
+                       {
+                               page.setFreezePageId(frozen);
+                       }
                }
        }
 
+       private boolean isAjax(Component component)
+       {
+               boolean isAjax = false;
+
+               Request request = component.getRequest();
+               if (request instanceof WebRequest)
+               {
+                       WebRequest webRequest = (WebRequest)request;
+                       isAjax = webRequest.isAjax();
+               }
+
+               return isAjax;
+       }
+
+
        /**
         * Method to call to register this interface for use
         */

Modified: 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
URL: 
http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java?rev=1044355&r1=1044354&r2=1044355&view=diff
==============================================================================
--- 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
 (original)
+++ 
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/handler/ListenerInterfaceRequestHandler.java
 Fri Dec 10 13:31:23 2010
@@ -154,29 +154,8 @@ public class ListenerInterfaceRequestHan
                                        new PageProvider(getPage()), policy));
                        }
 
-                       /*
-                        * FIXME WICKET-NG the handling of page id freezing 
should be generalized to
-                        * RequestListenerInterface, but we may have to 
refactor it to pass in the request cycle
-                        * into the invoke method so we can access the request 
and figure out if it is ajax or
-                        * not.
-                        */
-                       Boolean frozen = null;
+                       invokeListener();
 
-                       if (isAjax)
-                       {
-                               // do not increment page id for ajax requests
-                               frozen = page.setFreezePageId(true);
-                       }
-
-                       try
-                       {
-                               invokeListener();
-                       }
-                       finally
-                       {
-                               if (frozen != null)
-                                       page.setFreezePageId(frozen);
-                       }
                }
                else
                {


Reply via email to