0
我正在使用primefaces和JSF。我有一個可選的地址字段。如果用戶填寫任何一個字段(例如zip或name),則所有其他字段都是必需的。什麼是做這個驗證的最好方法。PrimeFaces驗證輸入組
我正在使用primefaces和JSF。我有一個可選的地址字段。如果用戶填寫任何一個字段(例如zip或name),則所有其他字段都是必需的。什麼是做這個驗證的最好方法。PrimeFaces驗證輸入組
您可以添加postValidate事件來驗證多個領域,如
<f:event listener="#{bean.validationMethod}" type="postValidate" />
<h:panelGroup id="xyz" rendered="#{facesContext.validationFailed}">
<h:message for="myform"/>
</h:panelGroup>
<h:panelGroup id="myform">
.......
<h:panelGroup>
在此之前型號的更新應該火,你可以用
FacesContext fc = FacesContext.getCurrentInstance();
UIComponent components = event.getComponent();
UIInput param1 = (UIInput) components.findComponent("param1");
UIInput param2 = (UIInput) components.findComponent("param2");
如果驗證得到不同的組件的新值失敗,請致電F acesContext.getCurrentInstance().validationFailed()
併爲myform添加消息。
如果不使用自定義的驗證,只是想以確保其他投入將特定輸入填充,那麼我會用Omnifaces validateAllOrNone,建議添加