我有一个导入函数,它将解析包含文档版本信息的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>
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);
}
}
当我点击“确定”时,动作不会触发。上面的代码有什么错误吗?
答案 0 :(得分:3)
在服务器处理期间,无法从客户端获得确认。
您有两种选择:
在调用您的操作方法之前获取覆盖权限,例如带有一个复选框“覆盖文件,如果存在?”或
您必须停止处理,设置标志并返回null以在浏览器中重新加载当前页面。
然后,您可以根据标志状态显示p:dialog
。
答案 1 :(得分:2)
您正面临典型的Primefaces问题。
当您的页面显示且buttonBean.showConfirm = false时,不会呈现此元素。这意味着,它不会出现在DOM树中。无论你以后做什么,都不能显示或隐藏不存在的元素。
实际上有两种方法可以解决你的问题。
答案 2 :(得分:0)
我遇到了非常相似的问题。我想出的解决方案是将逻辑拆分为2 - 首先,当按下按钮时,使用'action'准备验证数据并使用'oncomplete'运行远程命令,显示确认对话框,其中'好的'是真正的行动。
答案 3 :(得分:-1)
案例
按Delete按钮验证是否有所选项目。如果您打开一个弹出窗口,如果错误消息中没有显示,请咆哮。
<强>替代强>: (抱歉,我在发布代码时遇到了麻烦)
<强> XHTML 强>: View xhtml
<强> TestManageBean 强>: Manage bean