我有一个 p:commandButton
,单击它我需要向列表中添加一些值。在我的托管 bean 中,我正在验证必须添加的值,如果验证为 false,我必须显示一个确认弹出窗口。这是我的代码 -
<p:commandButton id="add" value="Add" type="submit" action="#{bean.doAdd}" ajax="false"
update=":List"/>
在 bean 中,单击“添加”按钮,
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 的弹出窗口吗?
最佳答案
您可以使用RequestContext
在托管bean中运行js代码
确保它是一个 ajax 调用 - 没有 ajax="false"
像这样
RequestContext context = RequestContext.getCurrentInstance();
context.execute("YourDialogwidgetVar.show()");
我假设您定义了一些对话框...
<p:confirmDialog id="confirmDialog" message="Hello"
header="Header" widgetVar="YourDialogwidgetVar">
</p:confirmDialog>
关于java - 根据条件单击按钮时显示确认弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13228351/