0

I'd like to call a javascript from bean of a dialog window, but it is executed twice!

I use the RequestContext.getCurrentInstance().execute() method. This method works perfectly if the page is not "Dialog Framework", but in external page dialog window the javascript is executed twice.

The parent page:

<h:form id="welcomeform">
  <p:commandButton  value="Welcome" actionListener="#{welcome.openhello()}" />
</h:form>

The parent bean:

@ManagedBean
public class Welcome {
    public void openhello() {
        Map<String,Object> options = new HashMap<String, Object>();
        options.put("modal", true);
        options.put("width", 300);
        options.put("height", 100);
        options.put("resizable", false);
        options.put("closable", true);
        RequestContext context = RequestContext.getCurrentInstance();
        context.openDialog("hello", options, null);
    }
}

The dialog page:

<h:body>        
    <h:form id="helloform">
        <p:commandButton    value="Hello" actionListener="#{hello.actionhello()}" />
    </h:form>
</h:body>

The dialog bean:

@ManagedBean(name = "hello")
public class Hello {
    public void actionhello() {
        RequestContext.getCurrentInstance().execute("alert('Hello World!');");
    }
}

The faces-config.xml:

    <action-listener>org.primefaces.application.DialogActionListener</action-listener>
    <navigation-handler>org.primefaces.application.DialogNavigationHandler</navigation-handler>
     <view-handler>org.primefaces.application.DialogViewHandler</view-handler>

The bigger problem with this twice execution of javascript, that RequestContext.getCurrentInstance().closeDialog(..) method also close twice, because it call the native PrimeFaces.closeDialog({pfdlgcid:'#{param.pfdlgcid}'}) script and if you use nested dialogs it will be close the parent dialog window too, not only the child dialog.

Primefaces version is 6.1 Server is Payara, browser is Chrome.

Any ideas what is going wrong here? Thanks in advance!

Linkman
  • 171
  • 1
  • 7

0 Answers0