【问题标题】:How to stop a message pop up confirm if validation fails如果验证失败,如何停止消息弹出确认
【发布时间】:2023-03-22 02:59:01
【问题描述】:

我有一个确认消息框,当一个人点击保存按钮时,它只是要求他们确认他们想要保存,但是即使所有验证都失败了也会弹出,有没有办法只如果所有验证都成功,则显示消息框

<p>
        <p:commandButton value="#{bundle.buttonSaveMark}"  icon ="ui-icon-disk" update="displayMark :growl" oncomplete="PF('dlg').show()" /> 
    </p>
    <p:dialog header="Confirm Mark" widgetVar="dlg" showEffect="fold" hideEffect="fold">  
        <h:panelGrid id="displayMark" columns="2" cellpadding="5">  
            <h:outputText value="Mark to be submitted: " />  
            <h:outputText value="#{selectedValue}"/>  
            <p:commandButton id="save"
                             value="#{bundle.buttonSave}"
                             actionListener ="#{markingBean.editMark}"
                             update="Navigation :growl"
                             icon="ui-icon-disk"
                             oncomplete="PF('nav').show()"/>
        </h:panelGrid>  
    </p:dialog>  

    <p:dialog header="Navigation" widgetVar="nav" showEffect="fold" hideEffect="fold">  
        <h:panelGrid id="Navigation" columns="2" cellpadding="5">  
            <h:outputText value="Return to this project's marking page: " />  
            <p:button id="go"
                      value="#{bundle.buttonProjMark}"
                      outcome ="/lecturer/marking/marking-index.xhtml?edit_id=#{markingBean.markToEdit.id}"
                      icon="ui-icon-clipboard"/>
            <h:outputText value="Return to staff homepage: " />  
            <p:button id="staffHome"
                      value="#{bundle.buttonStaffHome}"
                      outcome ="/index"
                      icon="ui-icon-home"/>
        </h:panelGrid>  
    </p:dialog>   

那是按钮,然后是确认

【问题讨论】:

    标签: javascript jquery jsf jsf-2 primefaces


    【解决方案1】:

    您可以使用 Java 代码更新导航对话框

    RequestContext.getCurrentInstance().update("Navigation");
    

    还可以从 java 代码中添加一个 callBackParam:

    RequestContext.getCurrentInstance().addCallbackParam("showDialog",true);
    

    将上述代码添加到您的 markingBean.editMark 操作中。如果验证失败,你的action不会被调用,所以callbackParam也不会被添加,这样对话框就不会出现。

    在客户端应该创建一个处理请求完成的js函数:

    function handle(args) {
        if (data != null && data.showDialog) {
            PF('nav').show()
        }
    }
    

    在按钮上:

    oncomplete="handle(args);"
    

    【讨论】:

    • 如果此解决方案适合您,请接受回答。所以其他人会知道这是一个封闭的问题。谢谢。
    猜你喜欢
    • 2014-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-30
    • 2020-04-10
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多