Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Component/s: Uncategorized
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      67

      Description

      I've seen a lot of users looking for a way to take an input field and "reset" it back to its initial state
      (talking back to the ValueBinding).

      This processing code commonly would live in an actionListener for an immediate UICommand. The first
      problem they run into (but don't understand) is that submittedValue is non-null at this point, so their
      attempts to call setValue(), etc., are futile. If they get past that (and ignore the Javadoc warning users
      not to call setSubmittedValue()!), then there's the subtleties of isLocalValueSet().

      A band-aid for the problem would be adding some sort of "reset()" or "resetValue()" to UIInput that
      would call the following three methods:

      • setValue(null)
      • setSubmittedValue(null)
      • setLocalValueSet(false)

        Issue Links

          Activity

          Hide
          Ed Burns added a comment -

          Seems reasonable and won't break backwards compatability.

          Show
          Ed Burns added a comment - Seems reasonable and won't break backwards compatability.
          Hide
          Ed Burns added a comment -

          accept.

          Show
          Ed Burns added a comment - accept.
          Hide
          Ed Burns added a comment -

          It's too bad we can't add this method to EditableValueHolder.

          Show
          Ed Burns added a comment - It's too bad we can't add this method to EditableValueHolder.
          Hide
          Ed Burns added a comment -

          [67-UIInputReset]

          This checkin implements the reset feature for UIInput.

          idea: adam.winer
          r=edburns

          M src/javax/faces/component/UIInput.java

          • add resetValue()
          • <p>Convenience method to reset this component's value to the
          • un-initialized state. This method does the following:</p>
            *
          • <p>Call {@link #setValue} passing <code>null</code>.</p>
            *
            * <p>Call {@link #setSubmittedValue} passing <code>null</code>.</p>
            *
            * <p>Call {@link #setLocalValueSet} passing <code>false</code>.</p>
            *
            * <p>Call {@link #setValid} passing <code>true</code>.</p>
            *
            * <p>Upon return from this call if the instance had a
            * <code>ValueBinding</code> associated with it for the "value"
            * property, this binding is evaluated when {@link * UIOutput#getValue} is called. Otherwise, <code>null</code> is
            * returned from <code>getValue()</code>.</p>

            M test/javax/faces/component/UIInputTestCase.java

            - test resetValue()


            Index: src/javax/faces/component/UIInput.java
            ===================================================================
            RCS file:
            /cvs/javaserverfaces-sources/jsf-api/src/javax/faces/component/UIInput.java,v
            retrieving revision 1.77
            diff -u -r1.77 UIInput.java
            — src/javax/faces/component/UIInput.java 10 Mar 2005 21:39:14 -0000 1.77
            +++ src/javax/faces/component/UIInput.java 22 Mar 2005 20:32:00 -0000
            @@ -179,6 +179,32 @@
            }

            /**
            + * <p>Convenience method to reset this component's value to the
            + * un-initialized state. This method does the following:</p>
            + *
            + * <p>Call {@link #setValue}

            passing <code>null</code>.</p>
            + *
            + * <p>Call

            {@link #setSubmittedValue}

            passing <code>null</code>.</p>
            + *
            + * <p>Call

            {@link #setLocalValueSet}

            passing <code>false</code>.</p>
            + *
            + * <p>Call

            {@link #setValid}

            passing <code>true</code>.</p>
            + *
            + * <p>Upon return from this call if the instance had a
            + * <code>ValueBinding</code> associated with it for the "value"
            + * property, this binding is evaluated when

            {@link + * UIOutput#getValue}

            is called. Otherwise, <code>null</code> is
            + * returned from <code>getValue()</code>.</p>
            + */
            +
            + public void resetValue()

            { + this.setValue(null); + this.setSubmittedValue(null); + this.setLocalValueSet(false); + this.setValid(true); + }

            +
            + /**

          • <p>The "localValueSet" state for this component.
            */
            private boolean localValueSet;
            Index: test/javax/faces/component/UIInputTestCase.java
            ===================================================================
            RCS file:
            /cvs/javaserverfaces-sources/jsf-api/test/javax/faces/component/UIInputTestCase.java,v
            retrieving revision 1.35
            diff -u -r1.35 UIInputTestCase.java
              • test/javax/faces/component/UIInputTestCase.java 7 Mar 2005 21:50:28 -0000 1.35
                +++ test/javax/faces/component/UIInputTestCase.java 22 Mar 2005 20:32:01 -0000
                @@ -333,6 +333,12 @@
                assertNull(input.getLocalValue());
                assertTrue(input.isValid());
                checkMessages(0);
                + input.resetValue();
                + assertNull(input.getLocalValue());
                + assertEquals("new command", input.getValue());
                + assertNull(input.getSubmittedValue());
                + assertTrue(input.isValid());
                + assertTrue(!input.isLocalValueSet());

          // Skip update on an invalid value
          input.setValid(false);

          Show
          Ed Burns added a comment - [67-UIInputReset] This checkin implements the reset feature for UIInput. idea: adam.winer r=edburns M src/javax/faces/component/UIInput.java add resetValue() <p>Convenience method to reset this component's value to the un-initialized state. This method does the following:</p> * <p>Call {@link #setValue} passing <code>null</code>.</p> * * <p>Call {@link #setSubmittedValue} passing <code>null</code>.</p> * * <p>Call {@link #setLocalValueSet} passing <code>false</code>.</p> * * <p>Call {@link #setValid} passing <code>true</code>.</p> * * <p>Upon return from this call if the instance had a * <code>ValueBinding</code> associated with it for the "value" * property, this binding is evaluated when {@link * UIOutput#getValue} is called. Otherwise, <code>null</code> is * returned from <code>getValue()</code>.</p> M test/javax/faces/component/UIInputTestCase.java - test resetValue() Index: src/javax/faces/component/UIInput.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-api/src/javax/faces/component/UIInput.java,v retrieving revision 1.77 diff -u -r1.77 UIInput.java — src/javax/faces/component/UIInput.java 10 Mar 2005 21:39:14 -0000 1.77 +++ src/javax/faces/component/UIInput.java 22 Mar 2005 20:32:00 -0000 @@ -179,6 +179,32 @@ } /** + * <p>Convenience method to reset this component's value to the + * un-initialized state. This method does the following:</p> + * + * <p>Call {@link #setValue} passing <code>null</code>.</p> + * + * <p>Call {@link #setSubmittedValue} passing <code>null</code>.</p> + * + * <p>Call {@link #setLocalValueSet} passing <code>false</code>.</p> + * + * <p>Call {@link #setValid} passing <code>true</code>.</p> + * + * <p>Upon return from this call if the instance had a + * <code>ValueBinding</code> associated with it for the "value" + * property, this binding is evaluated when {@link + * UIOutput#getValue} is called. Otherwise, <code>null</code> is + * returned from <code>getValue()</code>.</p> + */ + + public void resetValue() { + this.setValue(null); + this.setSubmittedValue(null); + this.setLocalValueSet(false); + this.setValid(true); + } + + /** <p>The "localValueSet" state for this component. */ private boolean localValueSet; Index: test/javax/faces/component/UIInputTestCase.java =================================================================== RCS file: /cvs/javaserverfaces-sources/jsf-api/test/javax/faces/component/UIInputTestCase.java,v retrieving revision 1.35 diff -u -r1.35 UIInputTestCase.java test/javax/faces/component/UIInputTestCase.java 7 Mar 2005 21:50:28 -0000 1.35 +++ test/javax/faces/component/UIInputTestCase.java 22 Mar 2005 20:32:01 -0000 @@ -333,6 +333,12 @@ assertNull(input.getLocalValue()); assertTrue(input.isValid()); checkMessages(0); + input.resetValue(); + assertNull(input.getLocalValue()); + assertEquals("new command", input.getValue()); + assertNull(input.getSubmittedValue()); + assertTrue(input.isValid()); + assertTrue(!input.isLocalValueSet()); // Skip update on an invalid value input.setValid(false);
          Hide
          Ed Burns added a comment -

          fixed

          Show
          Ed Burns added a comment - fixed
          Hide
          Ed Burns added a comment -

          Prepare to delete api subcomponent

          Show
          Ed Burns added a comment - Prepare to delete api subcomponent
          Hide
          Ed Burns added a comment -

          Move all to 1.2

          Show
          Ed Burns added a comment - Move all to 1.2
          Hide
          Manfred Riem added a comment -

          Closing resolved issue out

          Show
          Manfred Riem added a comment - Closing resolved issue out

            People

            • Assignee:
              Ed Burns
              Reporter:
              adamwiner
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: