0

我有一个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 的弹出窗口吗?

4

2 回答 2

2

您可以使用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> 
于 2012-11-05T09:05:26.280 回答
0

此代码可能对您有所帮助。

private boolean valid = true; 

public void doAdd() {
    valid = false;
}


<p:dialog id="basicDialog" header="Basic Dialog" visible="#{!testBean.valid}">
    <h:outputText value="Message!" />
</p:dialog>

<h:commandButton id="modalDialogButton" value="Modal" action="#{testBean.doAdd}"/>
于 2012-11-05T10:58:33.743 回答