click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sa...@apache.org
Subject svn commit: r922727 - in /click/trunk/click: documentation/docs/roadmap-changes.html framework/src/org/apache/click/control/Field.java framework/test/org/apache/click/control/FieldTest.java framework/test/org/apache/click/control/TextFieldTest.java
Date Sun, 14 Mar 2010 02:18:56 GMT
Author: sabob
Date: Sun Mar 14 02:18:56 2010
New Revision: 922727

URL: http://svn.apache.org/viewvc?rev=922727&view=rev
Log:
added Field trim property. CLK-627

Removed:
    click/trunk/click/framework/test/org/apache/click/control/FieldTest.java
Modified:
    click/trunk/click/documentation/docs/roadmap-changes.html
    click/trunk/click/framework/src/org/apache/click/control/Field.java
    click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java

Modified: click/trunk/click/documentation/docs/roadmap-changes.html
URL: http://svn.apache.org/viewvc/click/trunk/click/documentation/docs/roadmap-changes.html?rev=922727&r1=922726&r2=922727&view=diff
==============================================================================
--- click/trunk/click/documentation/docs/roadmap-changes.html (original)
+++ click/trunk/click/documentation/docs/roadmap-changes.html Sun Mar 14 02:18:56 2010
@@ -129,17 +129,26 @@ includes improved Ajax support and @Bind
       <li class="change">
         Added methods to Fields for styling their labels. See new methods
         <a href="click-api/org/apache/click/control/Field.html#setLabelStyle(java.lang.String)">Field.setLabelStyle(String)</a>
-        and <a href="click-api/org/apache/click/control/Field.html#setLabelStyleClass(java.lang.String)">Field.setLabelStyleClass(String)</a>
+        and <a href="click-api/org/apache/click/control/Field.html#setLabelStyleClass(java.lang.String)">Field.setLabelStyleClass(String)</a>.
+        This issue was raised by Stefax
         [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-595">CLK-595</a>].
       </li>
       <li class="change">
         Added methods to Fields for providing styling hints to their
         containing elements. See new methods
         <a href="click-api/org/apache/click/control/Field.html#setParentStyleHint(java.lang.String)">Field.setParentStyleHint(String)</a>
-        and <a href="click-api/org/apache/click/control/Field.html#setParentStyleClassHint(java.lang.String)">Field.setParentStyleClassHint(String)</a>
+        and <a href="click-api/org/apache/click/control/Field.html#setParentStyleClassHint(java.lang.String)">Field.setParentStyleClassHint(String)</a>.
+        This issue was raised by Stefax
         [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-595">CLK-595</a>].
       </li>
       <li class="change">
+        Added trim property to Field for controlling if the Field request
+        parameter is trimmed or not. See new method
+        <a href="click-api/org/apache/click/control/Field.html#setTrim(boolean)">Field.setTrim(boolean)</a>.
+        This issue was raised by Andrey Rybin
+        [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-627">CLK-627</a>].
+      </li>
+      <li class="change">
         Added new Context methods
         <a href="click-api/org/apache/click/Context.html#hasRequestParameter(java.lang.String)">Context.hasRequestParameter(String)</a>
         and <a href="click-api/org/apache/click/Context.html#hasRequestAttribute(java.lang.String)">Context.hasRequestAttribute(String)</a>.
@@ -150,7 +159,8 @@ includes improved Ajax support and @Bind
       </li>
       <li class="change">
         Replaced multiple ClickUtils close methods with a single method accepting
-        a <a href="click-api/org/apache/click/util/ClickUtils.html#close(java.io.Closeable)">Closeable</a>
+        a <a href="click-api/org/apache/click/util/ClickUtils.html#close(java.io.Closeable)">Closeable</a>.
+        This issue was raised by Andrey Rybin
         [<a target="_blank" href="https://issues.apache.org/jira/browse/CLK-620">CLK-620</a>].
       </li>
     </ul>

Modified: click/trunk/click/framework/src/org/apache/click/control/Field.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/src/org/apache/click/control/Field.java?rev=922727&r1=922726&r2=922727&view=diff
==============================================================================
--- click/trunk/click/framework/src/org/apache/click/control/Field.java (original)
+++ click/trunk/click/framework/src/org/apache/click/control/Field.java Sun Mar 14 02:18:56
2010
@@ -229,8 +229,11 @@ public abstract class Field extends Abst
     /** The Field 'title' attribute, which acts as a tooltip help message. */
     protected String title;
 
+    /** The Field is trimmed flag, default value is true. */
+    protected boolean trim = true;
+
     /**
-     * The validate Field value <tt>onProcess()</tt> invokation flag.
+     * The validate Field value <tt>onProcess()</tt> invocation flag.
      */
     protected Boolean validate;
 
@@ -856,6 +859,27 @@ public abstract class Field extends Abst
     }
 
     /**
+     * Return true if the Field request value should be trimmed, false otherwise.
+     * The default value is <tt>"true"</tt>.
+     *
+     * @return true if the Field request value should be trimmed, false otherwise
+     */
+    public boolean isTrim() {
+        return trim;
+    }
+
+    /**
+     * Set the trim flag to true if the Field request value should be trimmed,
+     * false otherwise.
+     *
+     * @param trim true if the Field request value should be trimmed, false
+     * otherwise
+     */
+    public void setTrim(boolean trim) {
+        this.trim = trim;
+    }
+
+    /**
      * Return true if the Field should validate itself when being processed.
      * <p/>
      * If the validate attribute for the Field is not explicity set, this
@@ -1173,7 +1197,11 @@ public abstract class Field extends Abst
     protected String getRequestValue() {
         String value = getContext().getRequestParameter(getName());
         if (value != null) {
-            return value.trim();
+            if (isTrim()) {
+                return value.trim();
+            } else {
+                return value;
+            }
         } else {
             return "";
         }

Modified: click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java
URL: http://svn.apache.org/viewvc/click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java?rev=922727&r1=922726&r2=922727&view=diff
==============================================================================
--- click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java (original)
+++ click/trunk/click/framework/test/org/apache/click/control/TextFieldTest.java Sun Mar 14
02:18:56 2010
@@ -103,4 +103,151 @@ public class TextFieldTest extends TestC
         // Check that the value <script> is not rendered
         assertTrue(field.toString().indexOf(value) < 0);
     }
+
+    /**
+     * Check that TextField label style is rendered by Form and FieldSet.
+     *
+     * CLK-595
+     */
+    public void testLabelStyle() {
+        MockContext.initContext();
+
+        // Check that Form renders the field label style
+        Form form = new Form("form");
+        Field field = new TextField("field");
+        form.add(field);
+
+        field.setLabelStyle("color: green");
+        assertTrue(form.toString().contains("<label for=\"form_field\" style=\"color:
green\">"));
+
+        // Check that FieldSet renders the field label style
+        form = new Form("form");
+        FieldSet fs = new FieldSet("fs");
+        form.add(fs);
+        field = new TextField("field");
+        fs.add(field);
+
+        field.setLabelStyle("color: green");
+        assertTrue(fs.toString().contains("<label for=\"form_field\" style=\"color: green\">"));
+    }
+
+    /**
+     * Check that TextField label style class is rendered by Form and FieldSet.
+     *
+     * CLK-595
+     */
+    public void testLabelStyleClass() {
+        MockContext.initContext();
+
+        // Check that Form renders the field label style
+        Form form = new Form("form");
+        Field field = new TextField("field");
+        form.add(field);
+
+        field.setLabelStyleClass("autumn");
+        assertTrue(form.toString().contains("<label for=\"form_field\" class=\"autumn\">"));
+
+        // Check that FieldSet renders the field label style
+        form = new Form("form");
+        // FieldStyle value should be overridden by the parentStyleHint below
+        form.setFieldStyle("font-weight:bold");
+        FieldSet fs = new FieldSet("fs");
+        form.add(fs);
+        field = new TextField("field");
+        fs.add(field);
+
+        field.setLabelStyleClass("autumn");
+        assertTrue(fs.toString().contains("<label for=\"form_field\" class=\"autumn\">"));
+    }
+
+    /**
+     * Check that TextField parent style hint is rendered by Form and FieldSet.
+     *
+     * CLK-595
+     */
+    public void testParentStyleHint() {
+        MockContext.initContext();
+
+        // Check that Form renders the field label style
+        Form form = new Form("form");
+        Field field = new TextField("field");
+        form.add(field);
+
+        field.setParentStyleHint("color: green");
+        // Check that style hint is rendered on the label and field cells
+        assertTrue(form.toString().contains("<td class=\"fields\" align=\"left\" style=\"color:
green\"><label"));
+        assertTrue(form.toString().contains("<td align=\"left\" style=\"color: green\"><input"));
+
+        // Check that FieldSet renders the field label style
+        form = new Form("form");
+        // FieldStyle value should be overridden by the parentStyleHint below
+        form.setFieldStyle("font-weight:bold");
+        FieldSet fs = new FieldSet("fs");
+        form.add(fs);
+        field = new TextField("field");
+        fs.add(field);
+
+        field.setParentStyleHint("color: green");
+        // Check that style hint is rendered on the label and field cells
+        assertTrue(fs.toString().contains("<td class=\"fields\" align=\"left\" style=\"color:
green\"><label"));
+        assertTrue(fs.toString().contains("<td align=\"left\" style=\"color: green\"><input"));
+    }
+
+    /**
+     * Check that TextField parent style class hint is rendered by Form and FieldSet.
+     *
+     * CLK-595
+     */
+    public void testParentStyleClassHint() {
+        MockContext.initContext();
+
+        // Check that Form renders the field label style
+        Form form = new Form("form");
+        Field field = new TextField("field");
+        form.add(field);
+
+        field.setParentStyleClassHint("autumn");
+        // Check that style class hint is rendered on the label and field cells
+        assertTrue(form.toString().contains("<td class=\"fields autumn\" align=\"left\"><label"));
+        assertTrue(form.toString().contains("<td class=\"autumn\" align=\"left\"><input"));
+
+        // Check that FieldSet renders the field label style
+        form = new Form("form");
+        FieldSet fs = new FieldSet("fs");
+        form.add(fs);
+        field = new TextField("field");
+        fs.add(field);
+
+        field.setParentStyleClassHint("autumn");
+        // Check that style class hint is rendered on the label and field cells
+        assertTrue(fs.toString().contains("<td class=\"fields autumn\" align=\"left\"><label"));
+        assertTrue(fs.toString().contains("<td class=\"autumn\" align=\"left\"><input"));
+    }
+
+    /**
+     * Test the TextField trim property behavior.
+     *
+     * CLK-627
+     */
+    public void testTrim() {
+         String trimmedValue = "value";
+         String value = " " + trimmedValue + " ";
+
+         MockContext context = MockContext.initContext();
+         context.getMockRequest().setParameter("field", value);
+
+        Field field = new TextField("field");
+        field.onProcess();
+
+        // Check that the field trims its request value
+        assertEquals(trimmedValue, field.getValue());
+
+        // Test again, this time switching off the trim property
+        field = new TextField("field");
+        field.setTrim(false);
+        field.onProcess();
+
+        // Check that field does not trim its request value
+        assertEquals(value, field.getValue());
+    }
 }



Mime
View raw message