如何在完成时在PrimeFaces中触发args.validationFailed [英] How to trigger args.validationFailed in PrimeFaces oncomplete

查看:64
本文介绍了如何在完成时在PrimeFaces中触发args.validationFailed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按下Save按钮时,应验证 actionsDialog 中的数据.如果输入了所需的信息并有效,则将显示另一个对话框,称为 reasonDialog .

When the Save button is pressed, the data from the actionsDialog should be validated. If the required information is entered and valid, a second dialog called reasonDialog would be displayed.

已保存对象的非JSF验证是通过一种返回错误消息列表的方法来完成的.如果验证失败,则会在FacesMessage中显示错误消息.我应该如何在objectsBean.validate中触发oncomplete中的if else子句?

Non-JSF validation of the saved object is done with a method that returns a list of error messages. I case the validation fails the errors messages are displayed with FacesMessage. How should I do in objectsBean.validate to trigger the if else clause from oncomplete?

<p:dialog id="actionsDialog" widgetVar="actionsDialog" dynamic="true" 
    resizable="false" width="800" modal="true">
    <ui:include src="/WEB-INF/flows/custom-flow/genericObject.xhtml"/>
    <f:facet name="footer">
        <p:commandButton value="Save" update="msgs"
            oncomplete="if (args.validationFailed) {reasonDialog.hide()} else {reasonDialog.show()}"
            actionListener="#{objectsBean.validate}"/>
        <p:commandButton value="Cancel" immediate="true" oncomplete="actionsDialog.hide()" />
    </f:facet>
</p:dialog>

推荐答案

如果使用JSF内置的验证工具(即仅使用验证器,并以通常的方式抛出ValidatorException并在其中插入所需的人脸消息),实际上是不可行的出于某种原因(关于JSF验证工具,我真的要三思而后行,三次),那么您始终可以使用

If utilizing the JSF-builtin validation facility (i.e. just use validators which throw ValidatorException the usual way with therein the desired faces message) is really not an option for some reason (I'd really think twice, no, thrice about working around JSF validation facility), then you can always use FacesContext#validationFailed() to signal JSF that the validation has failed in general, which is exactly what JSF validation facility is doing under the covers when a ValidatorException is caught.

FacesContext.getCurrentInstance().validationFailed();

这篇关于如何在完成时在PrimeFaces中触发args.validationFailed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆