click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r773952 - in /incubator/click/trunk/click/framework/src/org/apache/click: ClickServlet.java ControlRegistry.java
Date Tue, 12 May 2009 16:03:50 GMT
Author: sabob
Date: Tue May 12 16:03:50 2009
New Revision: 773952

URL: http://svn.apache.org/viewvc?rev=773952&view=rev
Log:
Added callback for control registry to handle exceptions.

Modified:
    incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java
    incubator/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java

Modified: incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java?rev=773952&r1=773951&r2=773952&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/ClickServlet.java Tue May 12
16:03:50 2009
@@ -490,10 +490,8 @@
             ErrorPage errorPage = (ErrorPage) page;
             errorPage.setMode(configService.getApplicationMode());
 
-            // Clear the POST_ON_PROCESS_EVENT control listeners from the registry
-            // Registered listeners from other phases must still be invoked
-            controlRegistry.getEventHolder(
-                ControlRegistry.POST_ON_PROCESS_EVENT).clear();
+            // Notify the registry of the error
+            controlRegistry.errorOccurred(errorPage.getError());
         }
 
         boolean continueProcessing = performOnSecurityCheck(page, context);

Modified: incubator/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java?rev=773952&r1=773951&r2=773952&view=diff
==============================================================================
--- incubator/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java (original)
+++ incubator/click/trunk/click/framework/src/org/apache/click/ControlRegistry.java Tue May
12 16:03:50 2009
@@ -127,7 +127,7 @@
      * The <tt>POST_ON_PROCESS_EVENT</tt> is the event during which control
      * listeners will fire.
      */
-    public static final int POST_ON_PROCESS_EVENT = 1;
+    public static final int POST_ON_PROCESS_EVENT = 300;
 
     /**
      * Indicates the listener should fire <tt>AFTER</tt> the onRender event.
@@ -135,7 +135,7 @@
      * <tt>guaranteed</tt> to trigger, even when redirecting, forwarding or if
      * page processing is cancelled.
      */
-    public static final int POST_ON_RENDER_EVENT = 2;
+    public static final int POST_ON_RENDER_EVENT = 400;
 
     // -------------------------------------------------------------- Variables
 
@@ -185,6 +185,15 @@
     // ------------------------------------------------------ Protected Methods
 
     /**
+     * Allow the Registry to handle the error that occurred.
+     */
+    protected void errorOccurred(Throwable throwable) {
+        // Clear the POST_ON_PROCESS_EVENT control listeners from the registry
+        // Registered listeners from other phases must still be invoked
+        getEventHolder(ControlRegistry.POST_ON_PROCESS_EVENT).clear();
+    }
+
+    /**
      * Clear the registry.
      */
     protected void clearRegistry() {
@@ -218,11 +227,12 @@
      * @param context the request context
      * @param eventSourceList the list of source controls
      * @param eventListenerList the list of listeners to fire
+     * @param event the specific event which events to fire
      *
      * @return true if the page should continue processing or false otherwise
      */
     protected boolean fireActionEvents(Context context, List eventSourceList,
-        List eventListenerList) {
+        List eventListenerList, int event) {
 
         boolean continueProcessing = true;
 
@@ -230,7 +240,7 @@
             Control source = (Control) eventSourceList.get(i);
             ActionListener listener = (ActionListener) eventListenerList.get(i);
 
-            if (!listener.onAction(source)) {
+            if(!fireActionEvent(context, source, listener, event)) {
                 continueProcessing = false;
             }
         }
@@ -257,7 +267,7 @@
      * true if the page should continue processing.
      *
      * @param context the request context
-     * @param event the specific event which events to fire
+     * @param event the event which listeners to fire
      *
      * @return true if the page should continue processing or false otherwise
      */
@@ -267,6 +277,29 @@
     }
 
     /**
+     * Fire the action for the given listener and event source which
+     * return true if the page should continue processing.
+     * <p/>
+     * This method will be passed a listener and source of a specific event
+     * e.g. {@link #POST_ON_PROCESS_EVENT} or {@link #POST_ON_RENDER_EVENT}.
+     * event.
+     * <p/>
+     * This method can be overridden if you need to customize the way events
+     * are fired.
+     *
+     * @param context the request context
+     * @param source the source control
+     * @param listener the listener to fire
+     * @param event the specific event which events to fire
+     *
+     * @return true if the page should continue processing or false otherwise
+     */
+    protected boolean fireActionEvent(Context context, Control source,
+        ActionListener listener, int event) {
+        return listener.onAction(source);
+    }
+
+    /**
      * Return the EventHolder for the specified event.
      *
      * @param event the event which EventHolder to retrieve
@@ -283,6 +316,16 @@
         }
     }
 
+    /**
+     * Create a new EventHolder instance.
+     *
+     * @param event the EventHolder's event
+     * @return new EventHolder instance
+     */
+    protected EventHolder createEventHolder(int event) {
+        return new EventHolder(event);
+    }
+
     // ------------------------------------------------ Package Private Methods
 
     /**
@@ -292,7 +335,7 @@
      */
     EventHolder getPostProcessEventHolder() {
         if (postProcessEventHolder == null) {
-            postProcessEventHolder = new EventHolder();
+            postProcessEventHolder = createEventHolder(POST_ON_PROCESS_EVENT);
         }
         return postProcessEventHolder;
     }
@@ -304,7 +347,7 @@
      */
     EventHolder getPostRenderEventHolder() {
         if (postRenderEventHolder == null) {
-            postRenderEventHolder = new EventHolder();
+            postRenderEventHolder = createEventHolder(POST_ON_RENDER_EVENT);
         }
         return postRenderEventHolder;
     }
@@ -358,12 +401,26 @@
      */
     public class EventHolder {
 
+        /** The EventHolder's event. */
+        protected int event;
+
         /** The list of registered event sources. */
         private List eventSourceList;
 
         /** The list of registered event listeners. */
         private List eventListenerList;
 
+        // ------------------------------------------------------- Constructors
+
+        /**
+         * Create a new EventHolder for the given event.
+         *
+         * @param event the EventHolder's event 
+         */
+        public EventHolder(int event) {
+            this.event = event;
+        }
+
         /**
          * Register the event source and event ActionListener to be fired in the
          * specified event.
@@ -439,7 +496,7 @@
             }
 
             return ControlRegistry.this.fireActionEvents(context,
-                getEventSourceList(), getEventListenerList());
+                getEventSourceList(), getEventListenerList(), event);
         }
     }
 



Mime
View raw message