2 Replies Latest reply on Apr 26, 2012 11:13 AM by jn.colin

    disabling/enabling component with ajax not working

    jn.colin

      Hi

       

      I have a simple form with three fields; one checkbox and two text fields, one of which should be enabled when the checkbox is ticked. Using the <a4j:ajax> tag, I'm able to enable/disable it on the UI side, but on the backend side, the component is always disabled, which means that the request value are never set, don't get validated and don't get to the model. Here the code I'm using; the first component is the checkbox, the second is the text field to be disabled and the third is a simple textfield. If I tick the checkbox, the text field gets enabled, but when I submit the form, the value is always set to 1 (the default value). Could anyone help me with solving this?

       

      Many thanks

       

      Jean-Noël

       

       

        <h:panelGrid columns="3" styleClass="registerTable"

        columnClasses="registerColumn1,registerColumn2,registerColumn3">


        <h:outputLabel for="groupRegistration" value="Group registration" />

        <h:selectBooleanCheckbox id="groupRegistration"

        value="#{registrationBean.groupRegistration}"

        valueChangeListener="#{registrationBean.groupRegistrationValueChangeListener}">

        <a4j:ajax render="@this,numParticipants"></a4j:ajax>

        </h:selectBooleanCheckbox>

        <rich:message for="groupRegistration" ajaxRendered="true" />

       

        <h:outputLabel for="numParticipants" value="Number of participants" />

        <h:inputText id="numParticipants"

        disabled="#{!registrationBean.groupRegistration }"

        value="#{registrationBean.numParticipants}" width="5"

        converter="javax.faces.Integer" converterMessage="Invalid number">

        </h:inputText>

        <rich:message for="numParticipants" ajaxRendered="true" />

       

        <h:outputLabel for="firstName" value="Firstname" />

        <h:inputText id="firstName" value="#{registrationBean.firstName}"

                                              width="20">

        </h:inputText>

        <rich:message for="firstName" ajaxRendered="true" />

       

        </h:panelGrid>

        • 1. Re: disabling/enabling component with ajax not working
          healeyb

          The code is fine and I can think of only two things:

           

          1. Is the xhtml inside a h:form?

          2. I'd expect that you'd need to use @ViewScoped or @SessionScoped not @RequestScoped.

           

          Regards,

          Brendan.

          1 of 1 people found this helpful
          • 2. Re: disabling/enabling component with ajax not working
            jn.colin

            You are perfectly right, using ViewScoped instead of RequestScoped helped.

             

            But still I don't get what's going wrong when using a RequestScoped bean:

            1. I click the checkbox, with a partial submit that updates the model
            2. then, on the form submit, because the disabled attribute is dependent on the value updated at step 1, it should be set to true, and thus get the field validated and updated in the model too

             

            In other words, I don't understand why the textfield is still considered disabled on the backend, while it is enabled in the UI

             

            Regards

             

            Jean-Noël