tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drobia...@apache.org
Subject svn commit: r883087 - in /tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src: main/java/org/apache/tapestry5/corelib/components/Palette.java test/app1/PaletteDemo.tml test/java/org/apache/tapestry5/integration/IntegrationTests.java
Date Sun, 22 Nov 2009 14:51:56 GMT
Author: drobiazko
Date: Sun Nov 22 14:51:55 2009
New Revision: 883087

URL: http://svn.apache.org/viewvc?rev=883087&view=rev
Log:
TAP5-868: It is not possible to attach a validation event listener to a Palette (or other
<select> field)

Modified:
    tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
    tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/app1/PaletteDemo.tml
    tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java

Modified: tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java?rev=883087&r1=883086&r2=883087&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
(original)
+++ tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
Sun Nov 22 14:51:55 2009
@@ -26,6 +26,7 @@
 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
 import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newSet;
 import org.apache.tapestry5.json.JSONArray;
+import org.apache.tapestry5.services.ComponentDefaultProvider;
 import org.apache.tapestry5.services.Request;
 
 import java.util.Collections;
@@ -145,6 +146,8 @@
                            "name", getControlName());
 
             writeDisabled(writer, isDisabled());
+            
+            Palette.this.validate.render(writer);
 
             for (Object value : getSelected())
             {
@@ -218,12 +221,24 @@
      */
     @Environmental
     private RenderSupport renderSupport;
+    
+    @Environmental
+    private ValidationTracker tracker;
 
     /**
      * Needed to access query parameters when processing form submission.
      */
     @Inject
     private Request request;
+    
+    @Inject
+    private ComponentDefaultProvider defaultProvider;
+
+    @Inject
+    private ComponentResources componentResources;
+    
+    @Inject
+    private FieldValidationSupport fieldValidationSupport;
 
     private SelectModelRenderer renderer;
 
@@ -262,6 +277,17 @@
      */
     @Parameter(value = "10")
     private int size;
+    
+    /**
+     * The object that will perform input validation. The validate binding prefix is generally
used to provide
+     * this object in a declarative fashion.
+     * 
+     * @since 5.1.0.6
+     */
+    @Parameter(defaultPrefix = BindingConstants.VALIDATE)
+    @SuppressWarnings("unchecked")
+    private FieldValidator<Object> validate;
+
 
     /**
      * The natural order of elements, in terms of their client ids.
@@ -282,6 +308,9 @@
     protected void processSubmission(String elementName)
     {
         String parameterValue = request.getParameter(elementName + "-values");
+        
+        this.tracker.recordInput(this, parameterValue);
+
         JSONArray values = new JSONArray(parameterValue);
 
         // Use a couple of local variables to cut down on access via bindings
@@ -304,7 +333,16 @@
             selected.add(objectValue);
         }
 
-        this.selected = selected;
+        try 
+        {
+            this.fieldValidationSupport.validate(selected, this.componentResources, this.validate);
+            
+            this.selected = selected;
+        } 
+        catch (final ValidationException e) 
+        {
+            this.tracker.recordError(this, e.getMessage());
+        }
     }
 
     private void writeDisabled(MarkupWriter writer, boolean disabled)
@@ -398,6 +436,15 @@
 
         model.visit(visitor);
     }
+    
+    /**
+     * Computes a default value for the "validate" parameter using
+     * {@link org.apache.tapestry5.services.FieldValidatorDefaultSource}.
+     */
+    Binding defaultValidate() 
+    {
+       return this.defaultProvider.defaultValidatorBinding("selected", this.componentResources);
+    }
 
     // Avoids a strange Javassist bytecode error, c'est lavie!
     int getSize()
@@ -416,4 +463,10 @@
 
         return selected;
     }
+    
+    @Override
+    public boolean isRequired()
+    {
+        return validate.isRequired();
+    }
 }

Modified: tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/app1/PaletteDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/app1/PaletteDemo.tml?rev=883087&r1=883086&r2=883087&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/app1/PaletteDemo.tml (original)
+++ tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/app1/PaletteDemo.tml Sun
Nov 22 14:51:55 2009
@@ -13,7 +13,7 @@
 
 
             <t:palette t:id="languages" model="languageModel" reorder="reorder" encoder="languageEncoder"
-                       availableLabel="Languages Offered">
+                       availableLabel="Languages Offered" validate="required">
                 <t:parameter name="selectedLabel" xml:space="default">
                     Selected <t:if test="reorder">/ Ranked</t:if> Languages
                 </t:parameter>

Modified: tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=883087&r1=883086&r2=883087&view=diff
==============================================================================
--- tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++ tapestry/tapestry5/branches/5.1.0.x-dev/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Sun Nov 22 14:51:55 2009
@@ -1005,6 +1005,19 @@
         // causes an error in the js console but does not throw an exception here. optimally,
this would make the test case fail.
         doubleClick("//select[@id=\"languages-avail\"]/option[1]");
     }
+    
+    /**
+     * TAP5-868.
+     */
+    @Test
+    public void palette_component_client_validation()
+    {
+        start("Palette Demo", "reset");
+
+        click(SUBMIT);
+
+        assertBubbleMessage("languages", "You must provide a value for Languages.");
+    }
 
     @Test
     public void event_handler_return_types()



Mime
View raw message