I would like to set the required attribute based on the value in another text box.
Then just check that in the attribute required.
eg. if you want it to depend on whether another field is filled in or not:
<h:inputText value="#{bean.input1}" binding="#{input1}" />
<h:inputText value="#{bean.input2}" required="#{not empty input1.value}" />
Or, when it should be a specific value, for example, "Foo".
<h:inputText value="#{bean.input1}" binding="#{input1}" />
<h:inputText value="#{bean.input2}" required="#{input1.value == 'foo'}" />
Keep it simple.
source
share