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 2007/02/01 01:27:58 UTC

svn commit: r502059 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/corelib/base/ main/java/org/apache/tapestry/corelib/components/ main/resources/org/apache/tapestry/ main/resources/org/apache/tapestry/corelib/component...

Author: hlship
Date: Wed Jan 31 16:27:57 2007
New Revision: 502059

URL: http://svn.apache.org/viewvc?view=rev&rev=502059
Log:
Allow field components to specify a particular clientId to be used to generate the client-side id and element name.
Tweak the HTML output from the BeanEditForm component and create more default CSS to make it look somewhat "pretty".
Expose the BeanEditForm's inner Form component so that it is possible to record or clear error messages.
Add a clearError() method to Form to allow stored errors (and input) to be cleared before redisplaying a form.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Loop.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
    tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/base/AbstractField.java Wed Jan 31 16:27:57 2007
@@ -115,8 +115,11 @@
     /** Used a shared instance for all types of fields, for efficiency. */
     private static final ProcessSubmissionAction PROCESS_SUBMISSION_ACTION = new ProcessSubmissionAction();
 
+    @Parameter(value = "prop:componentResources.id", defaultPrefix="literal")
     private String _clientId;
 
+    private String _assignedClientId;
+
     private String _elementName;
 
     @Environmental
@@ -162,13 +165,16 @@
     @SetupRender
     final void setup()
     {
-        String id = _resources.getId();
+        // By default, use the component id as the (base) client id. If the clientid
+        // parameter is bound, then that is the value to use.
+        
+        String id = _clientId;
 
         // Often, these elementName and _clientId will end up as the same value. There are many
         // exceptions, including a form that renders inside a loop, or a form inside a component
         // that is used multiple times.
 
-        _clientId = _pageRenderSupport.allocateClientId(id);
+        _assignedClientId = _pageRenderSupport.allocateClientId(id);
         String elementName = _formSupport.allocateElementName(id);
 
         _formSupport.storeAndExecute(this, new SetupAction(elementName));
@@ -177,7 +183,7 @@
 
     public final String getClientId()
     {
-        return _clientId;
+        return _assignedClientId;
     }
 
     public final String getElementName()

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/BeanEditForm.java Wed Jan 31 16:27:57 2007
@@ -83,15 +83,19 @@
     @Inject
     private Block _enum;
 
+    @Component
+    private Form _form;
+
     @Component(parameters =
     { "value=valueForProperty", "label=prop:propertyEditModel.label",
             "encoder=valueEncoderForProperty", "model=selectModelForProperty",
-            "validate=prop:validateForProperty" })
+            "validate=prop:validateForProperty", "clientId=prop:propertyName" })
     private Select _select;
 
     @Component(parameters =
     { "value=valueForProperty", "label=prop:propertyEditModel.label",
-            "translate=prop:translateForProperty", "validate=prop:validateForProperty" })
+            "translate=prop:translateForProperty", "validate=prop:validateForProperty",
+            "clientId=prop:propertyName" })
     private TextField _textField;
 
     @Inject
@@ -105,6 +109,8 @@
 
     // Values that change with each change to the current property:
 
+    private String _propertyName;
+
     private PropertyEditModel _propertyEditModel;
 
     private Block _blockForProperty;
@@ -116,6 +122,11 @@
         return _model;
     }
 
+    public String getPropertyName()
+    {
+        return _propertyName;
+    }
+
     public void setPropertyName(String propertyName)
     {
         _propertyEditModel = _model.get(propertyName);
@@ -123,6 +134,8 @@
         _blockForProperty = null;
         _fieldForProperty = null;
 
+        _propertyName = propertyName;
+
         String editorType = _propertyEditModel.getEditorType();
 
         if (editorType.equals("text"))
@@ -142,11 +155,6 @@
         throw new IllegalArgumentException(_messages.format("no-editor", editorType, propertyName));
     }
 
-    public String getPropertyName()
-    {
-        return _propertyEditModel.getPropertyName();
-    }
-
     boolean onPrepareFromForm()
     {
         // Fire a new prepare event to be consumed by the container. This is the container's
@@ -175,7 +183,6 @@
 
         // Use the property name, not the field id, when locating
         // validation message overrides.
-        String overrideId = _propertyEditModel.getPropertyName();
         Messages overrideMessages = _resources.getContainerResources().getMessages();
 
         for (String constraint : _validationConstraintGenerator
@@ -190,7 +197,7 @@
                     _fieldForProperty,
                     validatorType,
                     constraintValue,
-                    overrideId,
+                    _propertyName,
                     overrideMessages,
                     _locale);
 
@@ -238,5 +245,10 @@
     {
         return new EnumSelectModel(_propertyEditModel.getPropertyType(), _resources
                 .getContainerResources().getMessages());
+    }
+
+    public Form getForm()
+    {
+        return _form;
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java Wed Jan 31 16:27:57 2007
@@ -429,4 +429,12 @@
     {
         _tracker = tracker;
     }
+
+    /**
+     * Invokes {@link ValidationTracker#clear()}.
+     */
+    public void clearErrors()
+    {
+        _tracker.clear();
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Loop.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Loop.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Loop.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Loop.java Wed Jan 31 16:27:57 2007
@@ -31,6 +31,7 @@
 import org.apache.tapestry.annotations.Inject;
 import org.apache.tapestry.annotations.Parameter;
 import org.apache.tapestry.annotations.SetupRender;
+import org.apache.tapestry.annotations.SupportsInformalParameters;
 import org.apache.tapestry.services.FormSupport;
 import org.apache.tapestry.services.Heartbeat;
 
@@ -43,6 +44,7 @@
  * full objects when there is not encoder, or as client-side objects when there is an encoder).
  */
 @ComponentClass
+@SupportsInformalParameters
 public class Loop
 {
     /** Setup command for non-volatile rendering. */
@@ -185,7 +187,7 @@
     @Environmental(false)
     private FormSupport _formSupport;
 
-    @Parameter(value="prop:componentResources.elementName", defaultPrefix="literal")
+    @Parameter(value = "prop:componentResources.elementName", defaultPrefix = "literal")
     private String _elementName;
 
     /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/corelib/components/BeanEditForm.html Wed Jan 31 16:27:57 2007
@@ -1,18 +1,20 @@
-<form t:type="Form" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd" class="t-beaneditor">
+<form t:id="form" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
     <t:comp type="Errors"/>
 
-    <div class="t-beaneditor-row" t:type="Loop" t:source="model.propertyNames" t:value="propertyName">
-        <t:comp type="Delegate" to="blockForProperty"/>
+    <div class="t-beaneditor">
+        <div class="t-beaneditor-row" t:type="Loop" t:source="model.propertyNames"
+            t:value="propertyName">
+            <t:comp type="Delegate" to="blockForProperty"/>
+        </div>
+        <div class="t-beaneditor-row">
+            <input type="submit" value="Create/Update"/>
+        </div>
     </div>
-    <div class="t-beaneditor-row">
-        <input type="submit" value="Create/Update"/>
-    </div>
-
     <t:block id="text">
-        <label t:type="Label" for="textField"/>                
+        <label t:type="Label" for="textField"/>
         <input t:id="textField"/>
     </t:block>
-    
+
     <t:block id="enum">
         <label t:type="Label" for="select"/>
         <input t:id="select"/>

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css Wed Jan 31 16:27:57 2007
@@ -121,3 +121,37 @@
   border: 1px solid silver;
   margin: 0px;
 }
+
+DIV.t-beaneditor
+{
+  display: block;
+  background: #ffc;
+  border: 2px solid silver;
+  padding: 2px;
+}
+
+FORM.t-beaneditor LABEL:after
+{
+  content: ":";
+}
+
+DIV.t-beaneditor-row
+{
+  padding: 4px 0px 2px 0px;
+}
+
+DIV.t-beaneditor LABEL:after
+{
+  vertical-align: middle;
+  content: ":";
+}
+
+DIV.t-beaneditor LABEL
+{
+  width: 10%;
+  display: block;
+  float: left;
+  text-align: right;
+  clear: left;
+  padding-right: 3px;
+}
\ No newline at end of file

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/WEB-INF/BeanEditorDemo.html Wed Jan 31 16:27:57 2007
@@ -1,7 +1,7 @@
 <t:comp type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
     <h1>BeanEditor Component Demo</h1>
     
-    <t:comp type="BeanEditForm" object="registrationData"/>
+    <t:comp id="edit" object="registrationData"/>
               
     <p>
         [<a t:type="ActionLink" t:id="clear">Clear Data</a>]

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/IntegrationTests.java Wed Jan 31 16:27:57 2007
@@ -714,10 +714,10 @@
                 "Everyone has to have a last name!",
                 "Year of Birth requires a value of at least 1900.");
 
-        _selenium.type("textField", "a");
-        _selenium.type("textField_0", "b");
-        _selenium.type("textField_1", "");
-        _selenium.select("select", "label=Martian");
+        _selenium.type("firstName", "a");
+        _selenium.type("lastName", "b");
+        _selenium.type("birthYear", "");
+        _selenium.select("sex", "label=Martian");
 
         clickAndWait(submitButton);
 
@@ -726,9 +726,9 @@
                 "You must provide at least 5 characters for Last Name.",
                 "You must provide a value for Year of Birth.");
 
-        _selenium.type("textField", "Howard");
-        _selenium.type("textField_0", "Lewis Ship");
-        _selenium.type("textField_1", "1966");
+        _selenium.type("firstName", "Howard");
+        _selenium.type("lastName", "Lewis Ship");
+        _selenium.type("birthYear", "1966");
 
         clickAndWait(submitButton);
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java?view=diff&rev=502059&r1=502058&r2=502059
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/BeanEditorDemo.java Wed Jan 31 16:27:57 2007
@@ -15,12 +15,17 @@
 package org.apache.tapestry.integration.app1.pages;
 
 import org.apache.tapestry.annotations.ApplicationState;
+import org.apache.tapestry.annotations.Component;
 import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.corelib.components.BeanEditForm;
 import org.apache.tapestry.integration.app1.data.RegistrationData;
 
 @ComponentClass
 public class BeanEditorDemo
 {
+    @Component
+    private BeanEditForm _edit;
+
     @ApplicationState
     private RegistrationData _data;
 
@@ -33,9 +38,10 @@
     {
         return "ViewRegistration";
     }
-    
+
     void onActionFromClear()
     {
         _data = null;
+        _edit.getForm().clearErrors();
     }
 }