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 on h:inputText fields. When submitting the form I want to skip(or ignore) the required validation check and still invoke the application. I do want to do the form data validation and show the errors based on some condition.
Basically I want to skip the validations and invoke the application when the form is submitted using an ajax call and do the validation when the form is submitted via clicking a submit button.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With