How to disable the required tag on a selectOneMenu when p:ajax event=change?

ε祈祈猫儿з 提交于 2019-12-05 13:47:55

Let the required attribute check if the command button is invoked. You can check that by the presence of the button's client ID in the request parameter map.

<p:selectOneMenu ... required="#{not empty param[save.clientId]}" />
...
<p:commandButton binding="#{save}" ... />

(note: code is as-is, you don't need a bean property for this)

If the command button is not invoked (but instead the ajax change listener is invoked), then the required attribute will evaluate false and everything will go as you intented.


Update: as per the comments, you intend to make them appear like required during render response all time. So, just add that check:

<p:selectOneMenu ... required="#{not empty param[save.clientId] or facesContext.currentPhaseId.ordinal eq 6}" />
...
<p:commandButton binding="#{save}" ... />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!