Enable / Disable inputText on selectOneRadio Primefaces/JSF

Posted: June 21, 2012 in web

P:ajax target should be on the input container (h:outputpanel) not the input itself or it will go crazy and not accept inputs.

<p:selectOneRadio id="custom-radio" layout="custom" value="#{payment.type}" required="true"
requiredMessage="Please select">
<f:selectItem itemValue="BALANCE" />
<f:selectItem itemValue="AMOUNT" />
<p:ajax update="input-other-amount" />
<h:panelGrid columns="2" >
<p:radioButton id="option-past-due" for="custom-radio"
itemIndex="0" />
<h:outputLabel for="option-past-due">
<p:radioButton id="option-other-amount"
for="custom-radio" itemIndex="2" />
<h:outputLabel for="option-other-amount" id="input-other-amount">
<p:inputText disabled="#{payment.type != 'AMOUNT'}" size="5" value="#{payment.amount}" /> Other Amount
  1. ewqoijow says:

    Thank You!

  2. pRS says:

    great post,thanks a lot

  3. saba says:

    doesnt work in IE7

  4. fernando marquez says:

    Hi, thanks a lot but what can i do if i want to enable again it doesn´t work. It just just work only if i submit the value with a command button

    • chawi3 says:

      Every time you click on Balance it should disable the inputtext. Clicking Amount should enable it back. Make sure you’re setting values on your backing bean and do the ajax update targeting the inputtext.

  5. Success says:

    Hi, great post, but I got a question now, why is it that when the input text is disabled dynamically on the form buidup, the text field no longer binds the input text to the backing bean property when enabled again?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s