2 Replies Latest reply: Apr 26, 2012 11:13 AM by Jean-Noel Colin RSS

disabling/enabling component with ajax not working

Jean-Noel Colin Newbie



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





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


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

  <h:selectBooleanCheckbox id="groupRegistration"



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


  <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">


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


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

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



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



  • 1. Re: disabling/enabling component with ajax not working
    Brendan Healey Master

    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.




  • 2. Re: disabling/enabling component with ajax not working
    Jean-Noel Colin Newbie

    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