You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2014/06/03 19:51:50 UTC

[2/4] git commit: Add a few extension hooks into the Form component

Add a few extension hooks into the Form component


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/20288583
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/20288583
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/20288583

Branch: refs/heads/master
Commit: 20288583b5bfa7a65b7093911db0a5ad8e1c40c8
Parents: d49ddd6
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Jun 3 10:14:20 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Jun 3 10:14:20 2014 -0700

----------------------------------------------------------------------
 .../tapestry5/corelib/components/Form.java      | 70 ++++++++++++++++++--
 1 file changed, 64 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/20288583/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
index 1347484..8625439 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
@@ -19,7 +19,9 @@ import org.apache.tapestry5.corelib.internal.ComponentActionSink;
 import org.apache.tapestry5.corelib.internal.FormSupportImpl;
 import org.apache.tapestry5.corelib.internal.InternalFormSupport;
 import org.apache.tapestry5.dom.Element;
-import org.apache.tapestry5.internal.*;
+import org.apache.tapestry5.internal.BeanValidationContext;
+import org.apache.tapestry5.internal.BeanValidationContextImpl;
+import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.services.FormControlNameManager;
 import org.apache.tapestry5.internal.services.HeartbeatImpl;
 import org.apache.tapestry5.internal.util.AutofocusValidationDecorator;
@@ -128,7 +130,7 @@ public class Form implements ClientElement, FormValidationControl
      * <a href="https://issues.apache.org/jira/browse/TAP5-1808">TAP5-1801</a>.
      */
     @Parameter("defaultTracker")
-    private ValidationTracker tracker;
+    protected ValidationTracker tracker;
 
     @Inject
     @Symbol(SymbolConstants.FORM_CLIENT_LOGIC_ENABLED)
@@ -388,8 +390,7 @@ public class Form implements ClientElement, FormValidationControl
                 try
                 {
                     value = URLDecoder.decode(value, "UTF-8");
-                }
-                catch (UnsupportedEncodingException e)
+                } catch (UnsupportedEncodingException e)
                 {
                     logger.error(String.format(
                             "Enable to decode parameter value for parameter %s in form %s",
@@ -472,6 +473,8 @@ public class Form implements ClientElement, FormValidationControl
             {"unchecked", "InfiniteLoopStatement"})
     Object onAction(EventContext context) throws IOException
     {
+        beforeProcessSubmit(context);
+
         tracker.clear();
 
         formSupport = new FormSupportImpl(resources, validationId);
@@ -520,7 +523,11 @@ public class Form implements ClientElement, FormValidationControl
             fireValidateEvent(EventConstants.VALIDATE, context, eventCallback);
 
             if (eventCallback.isAborted())
+            {
                 return true;
+            }
+
+            afterValidate();
 
             // Let the listeners know about overall success or failure. Most
             // listeners fall into
@@ -552,6 +559,8 @@ public class Form implements ClientElement, FormValidationControl
 
             resources.triggerContextEvent(EventConstants.SUBMIT, context, eventCallback);
 
+            afterSuccessOrFailure();
+
             if (eventCallback.isAborted())
             {
                 return true;
@@ -585,6 +594,52 @@ public class Form implements ClientElement, FormValidationControl
         }
     }
 
+    /**
+     * A hook invoked from {@link #onAction(org.apache.tapestry5.EventContext)} after the
+     * {@link org.apache.tapestry5.EventConstants#SUBMIT} or {@link org.apache.tapestry5.EventConstants#FAILURE} event has been triggered.
+     * <p/>
+     * This method will be invoked regardless of whether the submit or failure event was aborted.
+     * <p/>
+     * This implementation does nothing.
+     *
+     * @since 5.4
+     */
+
+    protected void afterSuccessOrFailure()
+    {
+
+    }
+
+    /**
+     * A hook invoked from {@link #onAction(org.apache.tapestry5.EventContext)} before any other setup.
+     * <p/>
+     * This implementation does nothing.
+     *
+     * @param context
+     *         as passed to {@code onAction()}
+     * @since 5.4
+     */
+    protected void beforeProcessSubmit(EventContext context)
+    {
+
+    }
+
+    /**
+     * A hook invoked from {@link #onAction(org.apache.tapestry5.EventContext)} after the
+     * {@link org.apache.tapestry5.EventConstants#VALIDATE} event has been triggered, and
+     * before the {@link #tracker} has been {@linkplain org.apache.tapestry5.ValidationTracker#clear() cleared}.
+     * <p/>
+     * Only invoked if the valiate event did not abort (that is, the no event handler method returned a value).
+     * <p/>
+     * This implementation does nothing.
+     *
+     * @since 5.4
+     */
+    protected void afterValidate()
+    {
+
+    }
+
     private boolean isFormCancelled()
     {
         // The "cancel" query parameter is reserved for this purpose; if it is present then the form was canceled on the
@@ -672,7 +727,10 @@ public class Form implements ClientElement, FormValidationControl
 
                     // Actions are a mix of ordinary actions and cancel actions.  Filter out one set or the other
                     // based on whether the form was submitted or cancelled.
-                    if (forFormCancel != cancelAction) { continue; }
+                    if (forFormCancel != cancelAction)
+                    {
+                        continue;
+                    }
 
                     component = source.getComponent(componentId);
 
@@ -765,7 +823,7 @@ public class Form implements ClientElement, FormValidationControl
         } catch (RuntimeException ex)
         {
             logger.error(
-                    String.format("Unable to obtrain form control names to preallocate: %s",
+                    String.format("Unable to obtain form control names to preallocate: %s",
                             ExceptionUtils.toMessage(ex)), ex);
         }
     }