tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r709521 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/base/ main/java/org/apache/tapestry5/corelib/components/ test/app1/ test/java/org/apache/tapestry5/integration/ test/java/org/apache/tapestry5/...
Date Fri, 31 Oct 2008 18:27:58 GMT
Author: hlship
Date: Fri Oct 31 11:27:57 2008
New Revision: 709521

URL: http://svn.apache.org/viewvc?rev=709521&view=rev
Log:
TAP5-87: PasswordField should not update its value parameter when the submitted value is blank

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlankPasswordDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BlankPasswordDemo.java
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PasswordField.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java?rev=709521&r1=709520&r2=709521&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractTextField.java
Fri Oct 31 11:27:57 2008
@@ -20,6 +20,7 @@
 import org.apache.tapestry5.corelib.mixins.RenderDisabled;
 import org.apache.tapestry5.ioc.AnnotationProvider;
 import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.ComponentDefaultProvider;
 import org.apache.tapestry5.services.Request;
 
@@ -202,7 +203,11 @@
 
             fieldValidationSupport.validate(translated, resources, validate);
 
-            value = translated;
+            // If the value provided is blank and we're ignoring blank input (i.e. PasswordField),
+            // then don't update the value parameter.
+
+            if (!(ignoreBlankInput() && InternalUtils.isBlank(rawValue)))
+                value = translated;
         }
         catch (ValidationException ex)
         {
@@ -210,6 +215,15 @@
         }
     }
 
+    /**
+     * Should blank input be ignored (after validation)?  This will be true for {@link
+     * org.apache.tapestry5.corelib.components.PasswordField}.
+     */
+    protected boolean ignoreBlankInput()
+    {
+        return false;
+    }
+
     @Override
     public boolean isRequired()
     {

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PasswordField.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PasswordField.java?rev=709521&r1=709520&r2=709521&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PasswordField.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/PasswordField.java
Fri Oct 31 11:27:57 2008
@@ -19,7 +19,8 @@
 
 /**
  * A version of {@link TextField}, but rendered out as an <input type="password">
element. Further, the output
- * value for a PasswordField is always blank.
+ * value for a PasswordField is always blank.  When the value provided to the PasswordField
is blank, it does not update
+ * its property (care should be taken that the "required" validator not be used in that case).
  * <p/>
  * Includes the <code>size</code> attribute, if a {@link org.apache.tapestry5.beaneditor.Width}
annotation is present on
  * the property bound to the value parameter.
@@ -43,9 +44,21 @@
                        "size", getWidth());
     }
 
+
     final void afterRender(MarkupWriter writer)
     {
         writer.end(); // input
     }
 
+    /**
+     * Returns true, blank input should be ignored and not cause an update to the server-side
property bound to the
+     * value parameter.
+     *
+     * @return true
+     */
+    @Override
+    protected boolean ignoreBlankInput()
+    {
+        return true;
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlankPasswordDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlankPasswordDemo.tml?rev=709521&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlankPasswordDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/BlankPasswordDemo.tml Fri Oct 31
11:27:57 2008
@@ -0,0 +1,18 @@
+<html t:type="border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+
+    <h1>Blank Password Demo</h1>
+
+    <p>
+        The password is:
+        <span id="visiblepassword">${password}</span>
+    </p>
+
+    <t:form>
+        <t:errors/>
+        <t:label for="password"/>
+        <t:passwordfield t:id="password"/>
+        <input type="submit" value="Update"/>
+    </t:form>
+
+</html>
\ No newline at end of file

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=709521&r1=709520&r2=709521&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
Fri Oct 31 11:27:57 2008
@@ -2400,4 +2400,26 @@
         assertTextPresent(
                 "Embedded component(s) form are defined within component class org.apache.tapestry5.integration.app1.pages.ComponentsNotInTemplateDemo");
     }
+
+    /**
+     * TAP5-87
+     */
+    public void blank_password_does_not_update()
+    {
+        start("Blank Password Demo");
+
+        type("password", "secret");
+
+        clickAndWait(SUBMIT);
+
+        assertFieldValue("password", "");
+
+        assertText("visiblepassword", "secret");
+
+        clickAndWait(SUBMIT);
+
+        assertFieldValue("password", "");
+
+        assertText("visiblepassword", "secret");
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BlankPasswordDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BlankPasswordDemo.java?rev=709521&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BlankPasswordDemo.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/BlankPasswordDemo.java
Fri Oct 31 11:27:57 2008
@@ -0,0 +1,25 @@
+//  Copyright 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.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+import org.apache.tapestry5.annotations.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+public class BlankPasswordDemo
+{
+    @Persist
+    @Property
+    private String password;
+}

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java?rev=709521&r1=709520&r2=709521&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Start.java
Fri Oct 31 11:27:57 2008
@@ -65,6 +65,9 @@
 
     private static final List<Item> ITEMS = CollectionFactory.newList(
 
+            new Item("BlankPasswordDemo", "Blank Password Demo",
+                     "Show that a blank value in a PasswordField does not update the server
side value."),
+
             new Item("GridFormEncoderDemo", "Grid Form Encoder Demo",
                      "Grid inside a Form using the PrimaryKeyEncoder option"),
 



Mime
View raw message