Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 如何从备份bean显示确认对话框(Primefaces)_Jsf 2_Primefaces - Fatal编程技术网

Jsf 2 如何从备份bean显示确认对话框(Primefaces)

Jsf 2 如何从备份bean显示确认对话框(Primefaces),jsf-2,primefaces,Jsf 2,Primefaces,我有一个导入函数,它将解析包含文档版本信息的XML文件,并将其保存在数据库中。如果用户试图上载已经存在的版本,我需要显示确认对话框,如“版本已经存在,是否要覆盖…”确定,取消 我正在使用Mozarra 2.0.3,Prime faces 2.2 RC2,Glass Fish 3,我正在尝试这种方法 <h:form id="conDialog"> <p:commandButton value="getConfirmMsg" update="conDialog" actio

我有一个导入函数,它将解析包含文档版本信息的XML文件,并将其保存在数据库中。如果用户试图上载已经存在的版本,我需要显示确认对话框,如“版本已经存在,是否要覆盖…”确定,取消

我正在使用Mozarra 2.0.3,Prime faces 2.2 RC2,Glass Fish 3,我正在尝试这种方法

<h:form id="conDialog">
    <p:commandButton value="getConfirmMsg" update="conDialog" action="#{buttonBean.getConfirmMsg()}" 
        oncomplete="confirmation.show()"/>
    <p:growl id="messages1" globalOnly="true"/>
    <p:confirmDialog message="Version already exists. Do you want to override it?"
        rendered="#{buttonBean.showConfirm}"
        header="Version already exist" severity="alert" widgetVar="confirmation">
        <p:commandButton value="OK" update="messages1" oncomplete="confirmation.hide()"
            action="#{buttonBean.overrideVersion}" />
        <p:commandButton value="Cancel" onclick="confirmation.hide()" type="button" />
    </p:confirmDialog>
</h:form>

当我点击“OK”时,动作没有触发。上述代码中是否有错误?

在服务器上处理期间,无法从客户端获得确认

您有两个选择:

  • 在调用您的操作方法之前获得覆盖权限,例如,使用复选框“覆盖文件(如果存在)”,或

  • 您必须停止处理,设置标志并返回null才能在浏览器中重新加载当前页面。 然后,您可以根据标志状态显示
    p:dialog

  • 案例

    按Delete(删除)按钮验证是否存在所选项目。如果打开弹出窗口,如果错误消息中未显示,则咆哮

    备选方案: (很抱歉,我无法发布代码)

    XHTML

    TestManageBean


    更多信息:

    您正面临典型的Primefaces问题

    当显示页面且buttonBean.showConfirm=false时,不会呈现此元素。这意味着,它不会出现在DOM树中。无论以后做什么,都无法显示或隐藏不存在的元素

    实际上有两种方法可以解决你的问题

  • 使用远程命令,以便从服务器传输未呈现的HTML代码
  • 使用css“display:none”代替rendered=“false”

  • 我面临着非常相似的问题。我提出的解决方案是将逻辑分为两部分-首先,当按下按钮时,使用“action”为验证准备数据,并使用“oncomplete”运行远程命令,其中显示确认对话框,其中“OK”是真正的操作。

    到目前为止,您尝试了什么?为了简单地显示一个对话框,您可以使用Primefaces
    p:dialog
    。嗨,Matt,我需要从服务器端执行此操作。如果(VersionExists){显示确认对话框。}@Veerendra命令按钮应该可以工作。浏览器中是否存在任何javascript错误?我可以使用,但它没有“update”属性。您确定没有调用您的方法或只是没有显示消息吗?添加:对于
    h:commandButton
    您必须将
    f:ajax
    render
    execute
    属性一起使用。@Veerendra我不知道。从未使用ClientBehaviorContext。(顺便说一句:你应该考虑你的提问策略。你提出一个问题,然后得到答案,然后编辑你的问题或添加更多后续问题的评论。这有时会奏效。但这会让那些试图帮助你的人失去动力。我的建议:如果你原来的问题的答案是可以接受的,那么接受它并打开一个新的答案关于后续问题的问题。)
    @ManagedBean
    @RequestScoped
    public class ButtonBean {
    
        boolean showConfirm = false;
    
        public boolean isShowConfirm() {
            return showConfirm;
        }
    
        public void setShowConfirm(boolean showConfirm) {
            this.showConfirm = showConfirm;
        }
    
        public void overrideVersion() {
            System.out.println("Version alrady exists...Overriding...");
            FacesMessage msg = new FacesMessage("Action is successful");
            FacesContext.getCurrentInstance().addMessage(null, msg);
        }
    
        public void getConfirmMsg() {
            System.out.println("Inside getConfirmMsg()....");
            showConfirm = true;
            System.out.println("showConfirm: " + showConfirm);
        }
    }