【问题标题】:Validation before Confirmation in jsfjsf中确认前的验证
【发布时间】:2012-10-26 10:12:31
【问题描述】:

我的代码如下:

 <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 的情况下在确认之前进行验证?

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 这里的“args”是什么?如何检查几个不同的控件(在解决方案 1 的情况下)?
    • 这是一个 JavaScript 参数对象,隐含在 PrimeFaces oncomplete 属性中。代码是完整的和原样的。您不需要在其他地方或其他地方定义它。您可以在 webbrowser 的内置 JS 调试器中看到它。你的第二个问题不清楚。不同的控制?什么?请详细说明。
    • 好的,我知道了。它工作得很好。谢谢一吨。但我的问题是我必须在显示确认对话框之前显示验证消息。现在我通过“”显示消息,但只有在按下确认对话框的确认按钮后才可见。发生 args.validationFailed 时如何执行它?
    • 你好,谁能告诉我如何在显示确认对话框之前显示验证结果??
    • 这很奇怪。我的回答显示了在出现验证错误时如何隐藏确认对话框的方法。尽管存在验证错误,它仍然会出现?也许您的代码中还有更多内容。
    猜你喜欢
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    相关资源
    最近更新 更多