1
votes

I'd like to open a dialog via the remotecommand action and get the value from the closeDialog(Object data) in the backing bean of the page. The remoteCommand is correctly firing the actionListener in the bb on page load

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

And the dialog is also correctly shown with this showDialog method:

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

And in the otherBean:

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

The problem is that I don't know how to listen to the event triggered by:

RequestContext.getCurrentInstance().closeDialog(user);

In the PF example http://www.primefaces.org/showcase/ui/dialogFrameworkData.jsf a commandButton and p:ajax is used like this

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

But I cannot put the p:ajax inside of the remoteCommand tag:

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

I've also tried to add the ajax behavior to a hidden commandButton, but the listener is never called that way. (of course I could do synchronization of data between the backing bean, but that would hurt the design of reusable dialog)

Is there some way how to work around that?

1

1 Answers

1
votes

I've solved the issue by creating hidden command button and calling javascript from remoteCommand:

<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>