Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.1, 1.2, 2.0, 2.1, 2.0 Rev a, 2.1 Rev a
    • Fix Version/s: 2.2 Sprint 14
    • Component/s: Lifecycle
    • Labels:
      None

      Description

      I'd like to discuss something I've been thinking about lately. How to clear forms easily when validation fails?

      Consider this simple case;

      <h:form>

      <h:messages />

      <h:inputText value="#

      {pprBean.firstname}" required="true"/>
      <h:inputText value="#{pprBean.surname}" required="true"/>

      <h:commandButton value="Save">
      <f:ajax render="@form" execute="@form"/>
      </h:commandButton>

      <h:commandButton value="Reset" actionListener="#{pprBean.reset}">
      <f:ajax render="@form" execute="@this"/>
      </h:commandButton>

      <h:outputText value="#{pprBean.firstname}

      " id="display" />

      </h:form>

      Bean;

      private String firstname, surname;

      public void reset()

      { firstname = null; surname = null; }

      So when you run this, if one of the field is empty and the other is not, validations fails and message is displayed. Problem happens when reset button is clicked to reset the form values. At processValidations phase UIInput saves the converted value at state
      and since validation failed, update model is not executed so local value is never cleared. Clicking reset, clears the bean's values but inputText will not use the bound value and use the one kept in state as well ending up a confusing behavior. I've seen this in many forums.

      I know wiki's like this;

      http://wiki.apache.org/myfaces/ClearInputComponents

      But I mean shouldn't this work as expected? Proposed solutions seem way too hard just to clear form values. (component binding and calling resetValue(), new view, javascript etc.)

      If at processValidations phase, local value is not stored in state, I think that will make the code above work, but I'm not sure if there will be any side effects. Does anyone know why converted local value is kept at state by calling setValue(). Both mojarra and myfaces keeps the value at state and I cannot find anything regarding this in spec, please point me if I'm wrong.

      Regards.

      Çağatay Çivici

        Issue Links

          Activity

          Ed Burns created issue -
          Ed Burns made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          Ed Burns made changes -
          Original Estimate 1 day, 6 hours [ 108000 ]
          Remaining Estimate 1 day, 6 hours [ 108000 ]
          Description I'd like to discuss something I've been thinking about lately. How to clear forms easily when validation fails?

          Consider this simple case;

          <h:form>

                         <h:messages />

                         <h:inputText value="#{pprBean.firstname}" required="true"/>
                         <h:inputText value="#{pprBean.surname}" required="true"/>

                         <h:commandButton value="Save">
                             <f:ajax render="@form" execute="@form"/>
                         </h:commandButton>

                         <h:commandButton value="Reset" actionListener="#{pprBean.reset}">
                             <f:ajax render="@form" execute="@this"/>
                         </h:commandButton>

                         <h:outputText value="#{pprBean.firstname}" id="display" />

          </h:form>

          Bean;

          private String firstname, surname;

             public void reset() {
                 firstname = null;
                 surname = null;
             }

          So when you run this, if one of the field is empty and the other is not, validations fails and message is displayed. Problem happens when reset button is clicked to reset the form values. At processValidations phase UIInput saves the converted value at state
          and since validation failed, update model is not executed so local value is never cleared. Clicking reset, clears the bean's values but inputText will not use the bound value and use the one kept in state as well ending up a confusing behavior. I've seen this in many forums.

          I know wiki's like this;

          http://wiki.apache.org/myfaces/ClearInputComponents

          But I mean shouldn't this work as expected? Proposed solutions seem way too hard just to clear form values. (component binding and calling resetValue(), new view, _javascript_ etc.)

          If at processValidations phase, local value is not stored in state, I think that will make the code above work, but I'm not sure if there will be any side effects. Does anyone know why converted local value is kept at state by calling setValue(). Both mojarra and myfaces keeps the value at state and I cannot find anything regarding this in spec, please point me if I'm wrong.

          Regards.

          Çağatay Çivici
          Ed Burns made changes -
          Comment [ See http://java.net/projects/javaserverfaces-spec-public/lists/jsr344-experts/archive/2011-06/message/0

          I'd like to discuss something I've been thinking about lately. How to clear forms easily when validation fails?

          Consider this simple case;

          <h:form>

                         <h:messages />

                         <h:inputText value="#{pprBean.firstname}" required="true"/>
                         <h:inputText value="#{pprBean.surname}" required="true"/>

                         <h:commandButton value="Save">
                             <f:ajax render="@form" execute="@form"/>
                         </h:commandButton>

                         <h:commandButton value="Reset" actionListener="#{pprBean.reset}">
                             <f:ajax render="@form" execute="@this"/>
                         </h:commandButton>

                         <h:outputText value="#{pprBean.firstname}" id="display" />

          </h:form>

          Bean;

          private String firstname, surname;

             public void reset() {
                 firstname = null;
                 surname = null;
             }

          So when you run this, if one of the field is empty and the other is not, validations fails and message is displayed. Problem happens when reset button is clicked to reset the form values. At processValidations phase UIInput saves the converted value at state
          and since validation failed, update model is not executed so local value is never cleared. Clicking reset, clears the bean's values but inputText will not use the bound value and use the one kept in state as well ending up a confusing behavior. I've seen this in many forums.

          I know wiki's like this;

          http://wiki.apache.org/myfaces/ClearInputComponents

          But I mean shouldn't this work as expected? Proposed solutions seem way too hard just to clear form values. (component binding and calling resetValue(), new view, _javascript_ etc.)

          If at processValidations phase, local value is not stored in state, I think that will make the code above work, but I'm not sure if there will be any side effects. Does anyone know why converted local value is kept at state by calling setValue(). Both mojarra and myfaces keeps the value at state and I cannot find anything regarding this in spec, please point me if I'm wrong.

          Regards.

          Çağatay Çivici ]
          Ed Burns made changes -
          Comment [ You might ask, "where in the spec does it require a call to
          setSubmittedValue(null)?" Well, it does in the part of the spec that
          deals with the
          javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL
          context-param. But otherwise calling setSubmittedValue(null) is not
          specifically mentioned. It should be. I've added that to
          1129-ClearInputValues. This is one problem.
          ]
          Ed Burns made changes -
          Ed Burns logged work - 03/Aug/12 7:45 PM
          • Time Spent:
            1 hour, 30 minutes
             
            <No comment>
          Ed Burns made changes -
          Remaining Estimate 1 day, 6 hours [ 108000 ] 1 day, 4 hours, 30 minutes [ 102600 ]
          Time Spent 1 hour, 30 minutes [ 5400 ]
          Ed Burns logged work - 06/Nov/12 4:08 AM
          • Time Spent:
            40 minutes
             
            M requestProcessingLifecycle.fm
            M JSF.book
            M preface.fm

            - In 2.2.6.1, require calling UIViewRoot.resetValues() if necessary.

            M jsf-api/src/main/resources/jsf.js

            - in request(), document options.resetInput.

            M jsf-ri/conf/share/facelets_jsf_core.tld

            - Document the resetInput attribute on f:ajax.

            - Document the new f:resetInput tag.

            M jsf-api/src/main/java/javax/faces/context/PartialViewContext.java

            - New method isResetValues().

            - New constant RESET_VALUES_PARAM_NAME

            M jsf-api/src/main/java/javax/faces/component/UIViewRoot.java

            - New method resetValues()
            Sending JSF.book
            Sending preface.fm
            Sending requestProcessingLifecycle.fm
            Transmitting file data ...
            Committed revision 1074.

            Committed to spec Framme Maker repo.
          Ed Burns made changes -
          Remaining Estimate 1 day, 4 hours, 30 minutes [ 102600 ] 1 day, 3 hours, 50 minutes [ 100200 ]
          Time Spent 1 hour, 30 minutes [ 5400 ] 2 hours, 10 minutes [ 7800 ]
          Ed Burns logged work - 06/Nov/12 4:15 AM
          • Time Spent:
            40 minutes
             
            M requestProcessingLifecycle.fm
            M JSF.book
            M preface.fm

            - In 2.2.6.1, require calling UIViewRoot.resetValues() if necessary.

            M jsf-api/src/main/resources/jsf.js

            - in request(), document options.resetInput.

            M jsf-ri/conf/share/facelets_jsf_core.tld

            - Document the resetInput attribute on f:ajax.

            - Document the new f:resetInput tag.

            M jsf-api/src/main/java/javax/faces/context/PartialViewContext.java

            - New method isResetValues().

            - New constant RESET_VALUES_PARAM_NAME

            M jsf-api/src/main/java/javax/faces/component/UIViewRoot.java

            - New method resetValues()
            Sending jsf-api/src/main/java/javax/faces/component/UIViewRoot.java
            Sending jsf-api/src/main/java/javax/faces/context/PartialViewContext.java
            Sending jsf-api/src/main/resources/jsf.js
            Sending jsf-ri/conf/share/facelets_jsf_core.tld
            Sending jsf-ri/src/main/java/com/sun/faces/context/PartialViewContextImpl.java
            Adding test/agnostic/lifecycle/basic/src/main/webapp/spec1129_resetInput_01.xhtml
            Transmitting file data ......
            Committed revision 10978.
          Ed Burns made changes -
          Remaining Estimate 1 day, 3 hours, 50 minutes [ 100200 ] 1 day, 3 hours, 10 minutes [ 97800 ]
          Time Spent 2 hours, 10 minutes [ 7800 ] 2 hours, 50 minutes [ 10200 ]
          Ed Burns made changes -
          Ed Burns made changes -
          Link This issue blocks JAVASERVERFACES-2576 [ JAVASERVERFACES-2576 ]
          Ed Burns made changes -
          Status In Progress [ 3 ] Closed [ 6 ]
          Fix Version/s 2.2 Sprint 14 [ 15353 ]
          Resolution Fixed [ 1 ]
          Hide
          Ed Burns added a comment -

          When sitting down to implement this, I discovered at least one additional aspect that must be specified. AjaxBehavior must have a boolean "resetInput" property.

          Show
          Ed Burns added a comment - When sitting down to implement this, I discovered at least one additional aspect that must be specified. AjaxBehavior must have a boolean "resetInput" property.
          Ed Burns made changes -
          Resolution Fixed [ 1 ]
          Status Closed [ 6 ] Reopened [ 4 ]
          Ed Burns logged work - 06/Dec/12 2:14 AM
          • Time Spent:
            2 hours, 14 minutes
             
            Part 1: implement the ajax case.

            Part 2 will be to implement the non-ajax case, including renaming
            f:resetInput to f:resetValues.

            SECTION: Specification changes
            ----------------------------

            M jsf-api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java

            - add resetValues boolean property.

            M jsf-api/src/main/java/javax/faces/context/PartialViewContext.java

            - change value of RESET_VALUES_PARAM_NAME to be
              javax.faces.partial.resetValues

            M jsf-api/src/main/java/javax/faces/component/UIInput.java

            - Add @Overrides

            M jsf-api/src/main/resources/jsf.js

            - change resetInput to resetValues, to match property on
              PartialViewContext.

            M jsf-ri/conf/share/facelets_jsf_core.tld

            - change f:ajax attribute name to resetValues from resetInput

            SECTION: Modified Files
            ----------------------------
            M jsf-ri/conf/share/tlddoc-resources/stylesheet.css

            - Attribute f:resetInput to 2.2.

            M jsf-ri/src/main/java/com/sun/faces/context/PartialViewContextImpl.java

            in processPartial():

            - fix "local variable hides field"

            - implement call to resetValues().

            M jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java
            M jsf-ri/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java

            - pass through resetValues so it gets rendered.

            Sending jsf-api/src/main/java/javax/faces/component/UIInput.java
            Sending jsf-api/src/main/java/javax/faces/component/behavior/AjaxBehavior.java
            Sending jsf-api/src/main/java/javax/faces/context/PartialViewContext.java
            Sending jsf-api/src/main/resources/jsf.js
            Sending jsf-ri/conf/share/facelets_jsf_core.tld
            Sending jsf-ri/conf/share/tlddoc-resources/stylesheet.css
            Sending jsf-ri/src/main/java/com/sun/faces/context/PartialViewContextImpl.java
            Sending jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/AjaxHandler.java
            Sending jsf-ri/src/main/java/com/sun/faces/renderkit/html_basic/AjaxBehaviorRenderer.java
            Transmitting file data .........
            Committed revision 11134.
          Ed Burns made changes -
          Remaining Estimate 1 day, 3 hours, 10 minutes [ 97800 ] 1 day, 56 minutes [ 89760 ]
          Time Spent 2 hours, 50 minutes [ 10200 ] 5 hours, 4 minutes [ 18240 ]
          Ed Burns logged work - 06/Dec/12 8:45 PM
          • Time Spent:
            1 hour, 39 minutes
             
            Implement resetValues

            SECTION: API Changes
            --------------------
            M jsf-ri/conf/share/facelets_jsf_core.tld
            M jsf-api/src/main/resources/jsf.js

            - rename f:resetInput to f:resetValues (and other similar changes) for
              parity with name of method on UIViewRoot.


            SECTION: Modified Files
            ----------------------------
            M jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/CoreLibrary.java

            + this.addTagHandler("resetValues", ResetValuesHandler.class);

            M jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ActionListenerHandler.java

            - extract superclass, ActionListenerHandlerBase, from this class, for use
              in new ResetValuesHandler.

            A + jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ActionListenerHandlerBase.jav

            - the base class for ActionListenerHandler and ResetValuesHandler.

            A + jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ResetValuesHandler.java
            a

            - New handler.

            A test/agnostic/lifecycle/basic/src/main/java/com/sun/faces/test/lifecycle/basic/Spec1129ResetInputBean.java
            A test/agnostic/lifecycle/basic/src/main/webapp/spec1129_resetInput_01.xhtml
            A test/agnostic/lifecycle/basic/src/main/webapp/WEB-INF/glassfish-web.xml

            - Test content. Need help from Cagatay.

            Sending jsf-api/src/main/resources/jsf.js
            Sending jsf-ri/conf/share/facelets_jsf_core.tld
            Sending jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ActionListenerHandler.java
            Adding jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ActionListenerHandlerBase.java
            Sending jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/CoreLibrary.java
            Adding jsf-ri/src/main/java/com/sun/faces/facelets/tag/jsf/core/ResetValuesHandler.java
            Adding test/agnostic/lifecycle/basic/src/main/java/com/sun/faces/test/lifecycle/basic/Spec1129ResetInputBean.java
            Adding test/agnostic/lifecycle/basic/src/main/webapp/WEB-INF/glassfish-web.xml
            Adding test/agnostic/lifecycle/basic/src/main/webapp/spec1129_resetInput_01.xhtml
            Transmitting file data .........
            Committed revision 11140.
          Ed Burns made changes -
          Remaining Estimate 1 day, 56 minutes [ 89760 ] 23 hours, 17 minutes [ 83820 ]
          Time Spent 5 hours, 4 minutes [ 18240 ] 6 hours, 43 minutes [ 24180 ]
          Hide
          Ed Burns added a comment -

          Need verification from Cagatay.

          Show
          Ed Burns added a comment - Need verification from Cagatay.
          Ed Burns made changes -
          Status Reopened [ 4 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Hide
          Manfred Riem added a comment -

          Closing resolved issue out

          Show
          Manfred Riem added a comment - Closing resolved issue out
          Manfred Riem made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1 day, 6 hours
                1d 6h
                Remaining:
                Time Spent - 6 hours, 43 minutes Remaining Estimate - 23 hours, 17 minutes
                23h 17m
                Logged:
                Time Spent - 6 hours, 43 minutes Remaining Estimate - 23 hours, 17 minutes
                6h 43m