4 Replies Latest reply on Apr 25, 2008 1:16 PM by Joao Viragine

    Form value submitted to server but not processed

    Martin Trummer Newbie

      <h:form id="form">
        Value1:<h:inputText id="it1" value="#{simpleBean.value1}" disabled="true" /><br />
        Value2:<h:inputText id="it2" value="#{simpleBean.value2}" disabled="false" /><br />
        <a onclick="document.getElementById('form:it1').disabled=false;">enable control</a>
        <h:commandButton value="submit" />
      </h:form>



      When this page is rendered the input text field for value1 is disabled. So I press the enable control link to enable the input text. Afterwards I submit the form but only the setter for value2 is called (but the value from it1 text field is submitted to the server).


      Can I change this behaviour?

        • 1. Re: Form value submitted to server but not processed
          Joao Viragine Newbie

          Martin,


          When inputText id1 is marked as disabled, the JSF don’t update the value for simpleBean.value1


          Note that this is desired behavior, JSF assume that the value never change once this is disabled.


          To reach what you want, I suggest something like this:



          <h:form id="form">
            Value1:<h:inputText id="it1" value="#{simpleBean.value1}" disabled="#{simpleBean.disabled}" /><br />
            Value2:<h:inputText id="it2" value="#{simpleBean.value2}" disabled="false" /><br />
            <a4j:commandLink action=#{some action method in simpleBean to change the value of disabled attribute} reRender="it1" immediate="true">enable control</ a4j:commandLink>
            <h:commandButton value="submit" />
          </h:form>




          Note the use of ajax to notify JSF about the changes.


          • 2. Re: Form value submitted to server but not processed
            Daniel Roth Apprentice

            I agree it seems a bit weird...


            You could solve it with something like this


            <h:form>
                 <h:inputText value="#{bean.str1}" />
                 <h:panelGroup id="a4j">
                      <h:inputText value="#{bean.str2}" disabled="#{bean.disabled}" />
                 </h:panelGroup>
                 <a:commandLink value="Enable" action="#{bean.enable}" reRender="a4j" />   
            </h:form>
            
            



            where enable() just sets disabled to false.

            • 3. Re: Form value submitted to server but not processed
              Martin Trummer Newbie

              Well, I was aware of the solution using ajax to re render the control but i had hoped there would be a solution to my problem without a round trip.


              But the fact that this is desired JSF behaviour already showed me that I have to do implement some kind of workaround (e.g. use readonly in combination with setting the background of the input text control so that it looks like beeing disabled).

              • 4. Re: Form value submitted to server but not processed
                Joao Viragine Newbie

                Martin,


                The readonly has the same effect as disabled.


                JSF is “smart” to avoid that disabled/readonly field get “hacked”.


                I think that there is no way to do what you wont without a round trip.


                You can “mimic” desired behavior using some javascripts but be aware that is not safe (user can transform disabled/readonly fields in enabled/write fields and the sever will accept this values)