Skip required validation and invoke the application

无人久伴 提交于 2020-01-27 04:27:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/19712743/skip-required-validation-and-invoke-the-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!