You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@click.apache.org by sa...@apache.org on 2010/07/19 10:38:37 UTC

svn commit: r965385 - /click/trunk/click/framework/src/org/apache/click/ClickServlet.java

Author: sabob
Date: Mon Jul 19 08:38:36 2010
New Revision: 965385

URL: http://svn.apache.org/viewvc?rev=965385&view=rev
Log:
moved ajax target control lookup into separate method

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

Modified: click/trunk/click/framework/src/org/apache/click/ClickServlet.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/ClickServlet.java?rev=965385&r1=965384&r2=965385&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/ClickServlet.java (original)
+++ click/trunk/click/framework/src/org/apache/click/ClickServlet.java Mon Jul 19 08:38:36 2010
@@ -1869,10 +1869,11 @@ public class ClickServlet extends HttpSe
     }
 
     /**
-     * Process all ajax controls and return true if the page should continue
+     * Process all Ajax controls and return true if the page should continue
      * processing, false otherwise.
      *
      * @param context the request context
+     * @param eventDispatcher the event dispatcher
      * @param controlRegistry the control registry
      * @return true if the page should continue processing, false otherwise
      */
@@ -1881,43 +1882,10 @@ public class ClickServlet extends HttpSe
 
         boolean continueProcessing = true;
 
-        Control ajaxTarget = null;
-
-        if (logger.isTraceEnabled()) {
-            logger.trace("   the following controls have been registered as potential Ajax targets:");
-            if (controlRegistry.hasAjaxTargetControls()) {
-                for (Control control : controlRegistry.getAjaxTargetControls()) {
-                    HtmlStringBuffer buffer = new HtmlStringBuffer();
-                    String controlClassName = ClassUtils.getShortClassName(control.getClass());
-                    buffer.append("      ").append(controlClassName);
-                    buffer.append(": name='").append(control.getName()).append("'");
-                    logger.trace(buffer.toString());
-                }
-            } else {
-                logger.trace("      *no* control has been registered");
-            }
-        }
-
-        for (Control control : controlRegistry.getAjaxTargetControls()) {
-
-            if (control.isAjaxTarget(context)) {
-                ajaxTarget = control;
-                // The first matching control will be processed. Multiple matching
-                // controls are not supported
-                break;
-            }
-        }
+        // Find the ajax target control for the Ajax request
+        Control ajaxTarget = getAjaxTarget(context, controlRegistry);
 
         if (ajaxTarget != null) {
-            if (logger.isTraceEnabled()) {
-                HtmlStringBuffer buffer = new HtmlStringBuffer();
-                buffer.append("   invoked: '");
-                buffer.append(ajaxTarget.getName()).append("' ");
-                String className = ClassUtils.getShortClassName(ajaxTarget.getClass());
-                buffer.append(className);
-                buffer.append(".isAjaxTarget() : true (target Ajax control found)");
-                logger.trace(buffer.toString());
-            }
 
             // Process the control
             if (!ajaxTarget.onProcess()) {
@@ -1939,12 +1907,6 @@ public class ClickServlet extends HttpSe
                     logger.trace("   *no* behavior was registered while processing the control");
                 }
             }
-        } else {
-
-            if (logger.isTraceEnabled()) {
-                String msg = "   *no* target control was found for Ajax request";
-                logger.trace(msg);
-            }
         }
 
         return continueProcessing;
@@ -2198,6 +2160,61 @@ public class ClickServlet extends HttpSe
     // Private methods --------------------------------------------------------
 
     /**
+     * Find and return the Ajax target control or null if no Ajax target was found.
+     *
+     * @param context the request context
+     * @param controlRegistry the control registry
+     * @return the target Ajax target control or null if no Ajax target was found
+     */
+    private Control getAjaxTarget(Context context, ControlRegistry controlRegistry) {
+
+        Control ajaxTarget = null;
+
+        if (logger.isTraceEnabled()) {
+            logger.trace("   the following controls have been registered as potential Ajax targets:");
+            if (controlRegistry.hasAjaxTargetControls()) {
+                for (Control control : controlRegistry.getAjaxTargetControls()) {
+                    HtmlStringBuffer buffer = new HtmlStringBuffer();
+                    String controlClassName = ClassUtils.getShortClassName(control.getClass());
+                    buffer.append("      ").append(controlClassName);
+                    buffer.append(": name='").append(control.getName()).append("'");
+                    logger.trace(buffer.toString());
+                }
+            } else {
+                logger.trace("      *no* control has been registered");
+            }
+        }
+
+        for (Control control : controlRegistry.getAjaxTargetControls()) {
+
+            if (control.isAjaxTarget(context)) {
+                ajaxTarget = control;
+                // The first matching control will be processed. Multiple matching
+                // controls are not supported
+                break;
+            }
+        }
+
+        if (logger.isTraceEnabled()) {
+            if (ajaxTarget == null) {
+                String msg = "   *no* target control was found for Ajax request";
+                logger.trace(msg);
+
+            } else {
+                HtmlStringBuffer buffer = new HtmlStringBuffer();
+                buffer.append("   invoked: '");
+                buffer.append(ajaxTarget.getName()).append("' ");
+                String className = ClassUtils.getShortClassName(ajaxTarget.getClass());
+                buffer.append(className);
+                buffer.append(".isAjaxTarget() : true (target Ajax control found)");
+                logger.trace(buffer.toString());
+            }
+        }
+
+        return ajaxTarget;
+    }
+
+    /**
      * Log the request parameter names and values.
      *
      * @param request the HTTP servlet request