1
votes

As I was experimenting with JSF 2.0 , i came across a scenario like this .

I have two text fields - based on input of first field an ajax call is fired using

<f:ajax ... />

After the response is back I am re rendering the second text field ..but i want to disable the second text field based on some server side validation of first field value.

I don't want to set the disabled using style based on a third property which is being set in the bean after validation.

Is there any alternative ways..

thanks in advance

1

1 Answers

4
votes

Bind the first input component to the view by binding attribute and use UIInput#isValid() in the disabled attribute of the second input field. It will return false if validation has failed on the given input component.

<h:inputText binding="#{input1}" value="#{bean.input1}">
    <f:validator validatorId="yourValidator" />
    <f:ajax event="blur" render="input2" />
</h:inputText>
<h:inputText id="input2" value="#{bean.input2}" disabled="#{!input1.valid}" />