1

I have a code as follows:

 <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> 

Now, how can I do validation before confirmation without effecting my bean?

4

1 回答 1

6

PrimeFacesargs.validationFailed在 ajax 响应中返回一个。您可以在oncomplete属性中检查。替换你onclick

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

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

<p:commandButton ... update="confirmDialog" />
<p:confirmDialog ... visible="#{facesContext.postback and not facesContext.validationFailed}" />
于 2012-10-26T10:42:13.883 回答