如何从辅助bean显示确认对话框(Primefaces)

nen*_*eni 7 primefaces jsf-2

我有一个导入函数,它将解析包含文档版本信息的XML文件并将其保存在数据库中.如果用户尝试上传已经存在的版本,我需要显示确认对话框,如"版本已经存在,你要覆盖吗?" 好的,取消.

我正在使用Mozarra 2.0.3,Prime面对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>
Run Code Online (Sandbox Code Playgroud)

BackingBean

@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);
    }
}
Run Code Online (Sandbox Code Playgroud)

当我点击"确定"时,动作不会触发.上面的代码有什么错误吗?

Mat*_*ndy 3

在服务器上处理期间不可能从客户端获得确认。

您有两个选择:

  1. 在调用操作方法之前获取覆盖权限,例如使用复选框“如果存在则覆盖文件?” 或者

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