我的代码如下:
<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?
答案 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}" />