带有RemoteCommand的PF Dialog框架

时间:2013-12-11 11:02:05

标签: ajax jsf primefaces

我想通过remotecommand操作打开一个对话框,并从页面支持bean中的closeDialog(Object data)获取值。 remoteCommand正在在页面加载中的bb中正确触发actionListener

<p:remoteCommand autoRun="true" actionListener="#{userManagerBB.showDialog}"/>

此对话框也使用此showDialog方法正确显示:

 public void showDialog(ActionEvent e){
    ...
        otherBean.openDialog(selectedUser);
 }

在otherBean中:

public void openDialog(SiteUser user) {
   ...
    RequestContext.getCurrentInstance().openDialog("userDialog", options, params);
}

问题在于我不知道如何听取由以下事件触发的事件:

RequestContext.getCurrentInstance().closeDialog(user);

在PF示例http://www.primefaces.org/showcase/ui/dialogFrameworkData.jsf中,commandButton和p:ajax就像这样使用

<p:commandButton value="Select Car" icon="ui-icon-extlink" actionListener="#{dialogBean.chooseCar}">  
    <p:ajax event="dialogReturn" listener="#{dialogBean.onCarChosen}" update="growl" />  
</p:commandButton>  

但我无法将p:ajax置于remoteCommand标记内:

<p:ajax> Unable to attach <p:ajax> to non-ClientBehaviorHolder parent

我还尝试将ajax行为添加到隐藏的commandButton中,但是从不以这种方式调用侦听器。 (当然我可以在支持bean之间进行数据同步,但这会损害可重用对话框的设计)

有什么方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我通过创建隐藏的命令按钮并从remoteCommand调用javascript解决了这个问题:

<p:remoteCommand autoRun="true" oncomplete="sync.jq.click()"/>

<p:commandButton widgetVar="sync" actionListener="#{userManagerBB.showDialog}" style="display:none" >
    <p:ajax event="dialogReturn" listener="#{userManagerBB.userChanged}" update="form"/>
</p:commandButton>