6 Replies Latest reply on Apr 15, 2009 4:57 AM by nimo22

    reset inputText-Values strange..

    nimo22

      How can I refresh inputText-Values, when a form is ajax-refreshed?

      I have a button

      <a4j:commandButton immediate="true" action ="{myBean.refresh} reRender="myForm"/>

      <h:myForm>
      <h:inputText id="myInputText" value="#{myInputValue}" validator=".."/>
      </h:myForm>

      class myBean{
      
      // I use seam
      @In(required="false") @Out(required="false")
      String myInputValue;
      
      void refresh(){
      
      myInputValue = "";
      
      }


      Even myInputValue is definitly set to an empty String, the inputText "myInputText" shows the old data (which was typed before invoking the reset-Button).

      What is the reason for such an odd behaviour?
      Should I use <a4j:form> ?

        • 1. Re: reset inputText-Values strange..
          nimo22

          The reRender is set to myForm (which definitly reRenders the form), but does not reset the inputText-Values:

          <h:form id="myForm">
          <h:inputText id="myInputText" value="#{myInputValue}" validator=".."/>
          </h:form>



          • 2. Re: reset inputText-Values strange..

            This is a expected JSF behaviour. What kind of form you use does not matter.
            Read this article about the source of your problem :
            http://www.jboss.org/community/docs/DOC-11866

            • 3. Re: reset inputText-Values strange..
              nimo22

              I found the failure, but I do not know, how to solve it.

              The problem is caused by <rich:ajaxValidator event="onblur"/>:

              Using this:

              <h:form id="myForm">
              <h:inputText id="myInputText" value="#{myInputValue}" required="true" validator="#{myBean.validateInputText}">
              <rich:ajaxValidator event="onblur"/>
              </h:inputText>
              <rich:message for="myInputText" />
              </h:form>


              the reset for "myInputText" does not really work!

              When using this (without ajaxValidator):

              <h:form id="myForm">
              <h:inputText id="myInputText" value="#{myInputValue}" required="true" validator="#{myBean.validateInputText}">
              <rich:message for="myInputText" />
              </h:form>



              the reset for "myInputText" does work!

              Is that normal? How can I use ajaxValidator and resetForm?



              • 4. Re: reset inputText-Values strange..
                nimo22

                Hello,

                I red that http://www.jboss.org/community/docs/DOC-11866.
                Indeed, my PhaseListener tells me that there is a (transient) value due to validating via ajax.
                Now, I do a normal validation on full form-submit (not ajax-validation) and the reset works.



                • 5. Re: reset inputText-Values strange..
                  nimo22

                  No it does not work. I use this (as suggested in http://wiki.apache.org/myfaces/ClearInputComponents ) to reset my form:

                  public void refresh() {
                   FacesContext context = FacesContext.getCurrentInstance();
                   Application application = context.getApplication();
                   ViewHandler viewHandler = application.getViewHandler();
                   UIViewRoot viewRoot = viewHandler.createView(context, context
                   .getViewRoot().getViewId());
                   context.setViewRoot(viewRoot);
                   context.renderResponse(); //Optional
                   }


                  However, I get something like this wyciwyg://6/http://localhost... in the addressbar and nothing works.

                  When I use a4j:commandButton type="reset", then my inputComponents becomes reset, but then after one second values are inserted what typed before firing the reset button. But my log tells me, that these inputFields are null. Even the action "resetForm" which does explicitly sets the inputFields to null does not help! I cannot use binding and reset the values via binding as I use Seams conversation..is there not a other possibility?

                  • 6. Re: reset inputText-Values strange..
                    nimo22

                    Okay, I have solved that via:

                    <a4j:commandButton type="reset" immediate="true" action="#{myBean.reset}" value="Reset">
                    <a4j:support event="onreset" reRender="form"/>
                    </a4j:commandButton>


                    without using ..findComponent();