Author: hlship
Date: Wed Nov  5 19:03:54 2008
New Revision: 711760

URL: http://svn.apache.org/viewvc?rev=711760&view=rev
Log:
TAP5-200: The Submit component doesn't need validation decoration

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DisabledFields.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DisabledFields.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/TestPageForSubmit.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java?rev=711760&r1=711759&r2=711760&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Submit.java
 Wed Nov  5 19:03:54 2008
@@ -14,15 +14,11 @@
 
 package org.apache.tapestry5.corelib.components;
 
-import org.apache.tapestry5.BindingConstants;
-import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.EventConstants;
+import org.apache.tapestry5.*;
 import org.apache.tapestry5.annotations.Environmental;
-import org.apache.tapestry5.annotations.Mixin;
 import org.apache.tapestry5.annotations.Parameter;
-import org.apache.tapestry5.corelib.base.AbstractField;
-import org.apache.tapestry5.corelib.mixins.RenderDisabled;
+import org.apache.tapestry5.annotations.SupportsInformalParameters;
+import org.apache.tapestry5.dom.Element;
 import org.apache.tapestry5.ioc.annotations.Inject;
 import org.apache.tapestry5.services.FormSupport;
 import org.apache.tapestry5.services.Heartbeat;
@@ -33,9 +29,9 @@
  * submit responsible for the form submission will post a notification that 
allows the application to know that it was
  * the responsible entity. The notification is named "selected" and has no 
context.
  */
-public class Submit extends AbstractField
[EMAIL PROTECTED]
+public class Submit implements ClientElement
 {
-
     /**
      * If true (the default), then any notification sent by the component will 
be deferred until the end of the form
      * submission (this is usually desirable).
@@ -50,6 +46,14 @@
     @Parameter(allowNull = false, defaultPrefix = BindingConstants.LITERAL)
     private String event = EventConstants.SELECTED;
 
+    /**
+     * If true, then the field will render out with a disabled attribute (to 
turn off client-side behavior). Further, a
+     * disabled field ignores any value in the request when the form is 
submitted.
+     */
+    @Parameter("false")
+    private boolean disabled;
+
+
     @Environmental
     private FormSupport formSupport;
 
@@ -62,9 +66,27 @@
     @Inject
     private Request request;
 
-    @SuppressWarnings("unused")
-    @Mixin
-    private RenderDisabled renderDisabled;
+    @Inject
+    private RenderSupport renderSupport;
+
+    private Element element;
+
+    private String clientId;
+
+    private static class ProcessSubmission implements ComponentAction<Submit>
+    {
+        private final String elementName;
+
+        public ProcessSubmission(String elementName)
+        {
+            this.elementName = elementName;
+        }
+
+        public void execute(Submit component)
+        {
+            component.processSubmission(elementName);
+        }
+    }
 
     public Submit()
     {
@@ -77,7 +99,17 @@
 
     void beginRender(MarkupWriter writer)
     {
-        writer.element("input", "type", "submit", "name", getControlName(), 
"id", getClientId());
+        clientId = null;
+
+        String name = formSupport.allocateControlName(resources.getId());
+
+        // Save the element, to see if an id is later requested.
+
+        element = writer.element("input", "type", "submit", "name", name);
+
+        if (disabled) writer.attributes("disabled", "disabled");
+
+        formSupport.store(this, new ProcessSubmission(name));
 
         resources.renderInformalParameters(writer);
     }
@@ -87,9 +119,10 @@
         writer.end();
     }
 
-    @Override
-    protected void processSubmission(String elementName)
+    void processSubmission(String elementName)
     {
+        if (disabled) return;
+
         String value = request.getParameter(elementName);
 
         if (value == null) return;
@@ -117,10 +150,29 @@
         this.defer = defer;
     }
 
-    void setup(ComponentResources resources, FormSupport support, Heartbeat 
heartbeat)
+    void setup(ComponentResources resources, FormSupport formSupport, 
Heartbeat heartbeat, RenderSupport renderSupport)
     {
         this.resources = resources;
-        formSupport = support;
+        this.formSupport = formSupport;
         this.heartbeat = heartbeat;
+        this.renderSupport = renderSupport;
+    }
+
+    /**
+     * Returns the component's client id. This must be called after the 
component has rendered. The id is allocated
+     * lazily (first time this method is invoked).
+     *
+     * @return client id for the component
+     */
+    public String getClientId()
+    {
+        if (clientId == null)
+        {
+            clientId = renderSupport.allocateClientId(resources);
+
+            element.forceAttributes("id", clientId);
+        }
+
+        return clientId;
     }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DisabledFields.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DisabledFields.tml?rev=711760&r1=711759&r2=711760&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DisabledFields.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DisabledFields.tml Wed 
Nov  5 19:03:54 2008
@@ -40,4 +40,8 @@
         <t:submit t:id="submit" disabled="true" value="Disabled Submit"/>
         <input type="submit" value="Continue"/>
     </t:form>
+
+    <p>
+        Submit id: ${submit.clientId}
+    </p>
 </html>
\ No newline at end of file

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java?rev=711760&r1=711759&r2=711760&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/corelib/components/SubmitTest.java
 Wed Nov  5 19:03:54 2008
@@ -59,7 +59,7 @@
 
         Submit submit = new Submit(request);
 
-        submit.setup(resources, support, null);
+        submit.setup(resources, support, null, null);
 
         submit.processSubmission(elementName);
 
@@ -92,7 +92,7 @@
 
         Submit submit = new Submit(request);
 
-        submit.setup(resources, support, heartbeat);
+        submit.setup(resources, support, heartbeat, null);
         submit.setDefer(false);
 
         submit.processSubmission(elementName);

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DisabledFields.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DisabledFields.java?rev=711760&r1=711759&r2=711760&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DisabledFields.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DisabledFields.java
 Wed Nov  5 19:03:54 2008
@@ -15,7 +15,10 @@
 package org.apache.tapestry5.integration.app1.pages;
 
 import org.apache.tapestry5.ValueEncoder;
+import org.apache.tapestry5.annotations.InjectComponent;
+import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.beaneditor.Validate;
+import org.apache.tapestry5.corelib.components.Submit;
 import org.apache.tapestry5.internal.services.StringValueEncoder;
 
 import java.util.Date;
@@ -31,12 +34,17 @@
 
     private List<String> values;
 
+    @InjectComponent
+    @Property
+    private Submit submit;
+
     @Validate("required")
     public String getStringValue()
     {
         return stringValue;
     }
 
+
     public void setStringValue(String stringValue)
     {
         this.stringValue = stringValue;

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/TestPageForSubmit.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/TestPageForSubmit.java?rev=711760&r1=711759&r2=711760&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/TestPageForSubmit.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app2/pages/TestPageForSubmit.java
 Wed Nov  5 19:03:54 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -69,4 +69,10 @@
         onSelectedFromCapitalize1();
     }
 
+    void afterRender()
+    {
+        // Force the generation of client ids.
+        capitalize1.getClientId();
+        capitalize2.getClientId();
+    }
 }


Reply via email to