问题描述
单击时有一个p:commandButton
,我需要在列表中添加一些值.在我的托管bean中,我正在验证必须添加的值,如果该值验证为false,则必须显示一个确认弹出窗口.这是我的代码-
I have a p:commandButton
on click of which I need to add a few values to a list. In my managed bean, I'm validating the value that has to be added, and if it validates to false, I have to display a confirmation popup. This is my code -
<p:commandButton id="add" value="Add" type="submit" action="#{bean.doAdd}" ajax="false"
update=":List"/>
然后在bean中,单击添加"按钮,
And in the bean, on click of the "Add" button,
public String doAdd() throws Exception {
if(response != null) {
if(keyList.contains(response)) {
if(!responseList.contains(response)) {
responseList.add(response);
}
} else {
//Have to display confirmation popup.
}
response = "";
}
return response;
}
我正在使用jsf 2.0和primefaces 3.0.有人可以告诉我如何显示Bean的弹出窗口吗?
I'm using jsf 2.0 and primefaces 3.0. Can someone please tell me how to display the popup from the bean?
推荐答案
您可以使用RequestContext
在托管bean中运行js代码
You can use RequestContext
to run js code inside your managed bean
确保它是ajax调用-没有ajax="false"
Make sure its an ajax call - got no ajax="false"
像这样
RequestContext context = RequestContext.getCurrentInstance();
context.execute("YourDialogwidgetVar.show()");
我认为您已经定义了一些对话框...
I assume you got some dialog defined...
<p:confirmDialog id="confirmDialog" message="Hello"
header="Header" widgetVar="YourDialogwidgetVar">
</p:confirmDialog>
这篇关于根据条件在按钮单击上显示确认弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!