I asked my question here but I think it lacks some obvious information. Hence I\'m posting my question again.
I have a JSF form which has some required validation o
Just put that condition straight in the required
attribute.
<h:inputText ... required="#{someCondition}" />
It namely just accepts any EL expression like as many other attributes. Many starters think that you can only hardcode a "true"
or "false"
string in it. This is untrue.
For example, when you want to let it evaluate true
only when the save button is actually pressed:
<h:inputText ... required="#{not empty param[save.clientId]}" />
...
<h:commandButton value="Cancel" ... />
<h:commandButton binding="#{save}" value="Save" ... />
(note: code is complete as-is, you do not need to bind it to a bean property)
This way the required
attribute only evaluates true
when the save button is pressed and it evaluates false
for any other button or ajax event listener.