如何从支持 bean 显示确认对话框(Primefaces) [英] How to display a confirmation dialog(Primefaces) from backing bean

查看:19
本文介绍了如何从支持 bean 显示确认对话框(Primefaces)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an import function which will parse the XML file which contains the version information of the document and save it in database. If user try to upload the already existing version, I need to show the confirmation dialog like " Version already exists do you wants to overwrite..?" ok, Cancel.

我使用的是 Mozarra 2.0.3、Prime faces 2.2 RC2、Glass Fish 3,我正在尝试这种方式.

I am using Mozarra 2.0.3, Prime faces 2.2 RC2, Glass Fish 3 and I am trying this way.

<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>

BackingBean

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);
    }
}

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

When I click on "OK" the action is not firing. Is there any mistake in the above code?

推荐答案

在服务器上处理期间无法得到客户端的确认.

It's not possible to get confirmation from the client during processing on server.

您有两个选择:

  1. 在调用您的操作方法之前获得覆盖权限,例如带有复选框如果存在则覆盖文件?"或

  1. Get overwrite permission before calling your action method e.g. with a checkbox "Overwrite file if exists?" or

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

You have to stop processing, set a flag and return null to reload current page in browser. Then you could display the p:dialog depending on flag status.

这篇关于如何从支持 bean 显示确认对话框(Primefaces)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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