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

查看:113
本文介绍了如何显示来自支持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面孔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天全站免登陆