Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

No easy way to "reset" an input component #67

Closed
glassfishrobot opened this issue Feb 3, 2005 · 12 comments
Closed

No easy way to "reset" an input component #67

glassfishrobot opened this issue Feb 3, 2005 · 12 comments

Comments

@glassfishrobot
Copy link

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)

Environment

Operating System: All
Platform: All

Affected Versions

[1.1]

@glassfishrobot
Copy link
Author

Reported by adamwiner

@glassfishrobot
Copy link
Author

Issue-Links:
blocks
JAVASERVERFACES_SPEC_PUBLIC-566

@glassfishrobot
Copy link
Author

@edburns said:
Seems reasonable and won't break backwards compatability.

@glassfishrobot
Copy link
Author

@edburns said:
accept.

@glassfishrobot
Copy link
Author

@edburns said:
It's too bad we can't add this method to EditableValueHolder.

@glassfishrobot
Copy link
Author

@edburns said:
[67-UIInputReset]

This checkin implements the reset feature for UIInput.

idea: adam.winer
r=edburns

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

  • add resetValue()

  • Convenience method to reset this component's value to the

  • un-initialized state. This method does the following:


    *

  • Call {@link #setValue} passing null.

    * *

    Call {@link #setSubmittedValue} passing null.

    * *

    Call {@link #setLocalValueSet} passing false.

    * *

    Call {@link #setValid} passing true.

    * *

    Upon return from this call if the instance had a * ValueBinding associated with it for the "value" * property, this binding is evaluated when {@link * UIOutput#getValue} is called. Otherwise, null is * returned from getValue().

    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 @@
    }

    /**

      • Convenience method to reset this component's value to the

      • un-initialized state. This method does the following:

    passing null.

      • Call

    {@link #setSubmittedValue}

    passing null.

      • Call

    {@link #setLocalValueSet}

    passing false.

      • Call

    {@link #setValid}

    passing true.

      • Upon return from this call if the instance had a

      • ValueBinding associated with it for the "value"
      • property, this binding is evaluated when

    {@link + * UIOutput#getValue}

    is called. Otherwise, null is

      • returned from getValue().

    • */
    • public void resetValue()

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

    • /**
  • 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);

@glassfishrobot
Copy link
Author

@edburns said:
fixed

@glassfishrobot
Copy link
Author

@edburns said:
Prepare to delete api subcomponent

@glassfishrobot
Copy link
Author

@edburns said:
Move all to 1.2

@glassfishrobot
Copy link
Author

Marked as fixed on Thursday, March 4th 2010, 6:09:29 am

@glassfishrobot
Copy link
Author

@manfredriem said:
Closing resolved issue out

@glassfishrobot
Copy link
Author

This issue was imported from java.net JIRA JAVASERVERFACES_SPEC_PUBLIC-67

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants