tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drobia...@apache.org
Subject svn commit: r831730 - in /tapestry/tapestry5/trunk/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, 01 Nov 2009 19:07:31 GMT
Author: drobiazko
Date: Sun Nov  1 19:07:31 2009
New Revision: 831730

URL: http://svn.apache.org/viewvc?rev=831730&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/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PaletteDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java?rev=831730&r1=831729&r2=831730&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Palette.java
Sun Nov  1 19:07:31 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,25 @@
      */
     @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 +278,16 @@
      */
     @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.2.0.0
+     */
+    @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,16 @@
 
         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 +464,10 @@
 
         return selected;
     }
+    
+    @Override
+    public boolean isRequired()
+    {
+        return validate.isRequired();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PaletteDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PaletteDemo.tml?rev=831730&r1=831729&r2=831730&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PaletteDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/PaletteDemo.tml Sun Nov  1 19:07:31
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/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=831730&r1=831729&r2=831730&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
Sun Nov  1 19:07:31 2009
@@ -14,6 +14,12 @@
 
 package org.apache.tapestry5.integration;
 
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
 import org.apache.tapestry5.corelib.components.Form;
 import org.apache.tapestry5.corelib.mixins.RenderDisabled;
 import org.apache.tapestry5.integration.app1.data.RegistrationData;
@@ -22,12 +28,6 @@
 import org.apache.tapestry5.test.AbstractIntegrationTestSuite;
 import org.testng.annotations.Test;
 
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-
 /**
  * Note: If these tests fail with BindException when starting Jetty, it could be Skype. At
least on my system, Skype is
  * listening on localhost:80.
@@ -1020,6 +1020,16 @@
         // 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]");
     }
+    
+    @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