在jsf中确认之前进行验证

时间:2012-10-26 10:12:31

标签: jsf jsf-2 primefaces

我的代码如下:

 <p:commandButton value="#{actualProductionEntry.val}" onclick="confirmation.show()"/>
 <p:confirmDialog id="confirmDialog" message="Are you sure?" header="Confirm Submission"                                 severity="alert" widgetVar="confirmation">         
     <p:commandButton id="confirm" value="Yes" oncomplete="confirmation.hide()" action="#   {actualProductionEntry.insert(login.userid,login.uid,login.dname,login.rptid)}"   update=":df:data :f1:p2 :dp:app"/>  
     <p:commandButton id="decline" value="No" onclick="confirmation.hide()" type="button" />                 
 </p:confirmDialog> 

现在,如何在确认之前进行验证而不影响我的bean?

1 个答案:

答案 0 :(得分:5)

PrimeFaces在ajax响应中返回args.validationFailed。您可以在oncomplete属性中检查该内容。将您的onclick替换为

<p:commandButton ... oncomplete="if (!args.validationFailed) confirmation.show()" />

或者,您可以让<p:commandButton>更新<p:confirmDialog>组件并检查其visible属性,如果FacesContext根据回复并且验证未失败:< / p>

<p:commandButton ... update="confirmDialog" />
<p:confirmDialog ... visible="#{facesContext.postback and not facesContext.validationFailed}" />