Jsf 2 如何从备份bean显示确认对话框(Primefaces)
我有一个导入函数,它将解析包含文档版本信息的XML文件,并将其保存在数据库中。如果用户试图上载已经存在的版本,我需要显示确认对话框,如“版本已经存在,是否要覆盖…”确定,取消 我正在使用Mozarra 2.0.3,Prime faces 2.2 RC2,Glass Fish 3,我正在尝试这种方法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
<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”时,动作没有触发。上述代码中是否有错误?在服务器上处理期间,无法从客户端获得确认 您有两个选择:
p:dialog
更多信息:您正面临典型的Primefaces问题 当显示页面且buttonBean.showConfirm=false时,不会呈现此元素。这意味着,它不会出现在DOM树中。无论以后做什么,都无法显示或隐藏不存在的元素 实际上有两种方法可以解决你的问题
我面临着非常相似的问题。我提出的解决方案是将逻辑分为两部分-首先,当按下按钮时,使用“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);
}
}