Search code examples
jsfjsf-2primefaces

Primefaces Dialog Framework: Dialog not opening


I am using dialog framework to open a new xhtml page on click on a command link. The problem is that the code to open dialog is executed but nothing happens.

My XHTML code that invokes new dialog.

<h:outputScript name="jquery/jquery-plugins.js" library="primefaces"/>
<h:outputScript name="jquery/jquery.js" library="primefaces"/>


<p:commandLink value="Create Customer">
    <p:ajax event="click" listener="#{bookingController.createCustomer}" />
</p:commandLink>

Invoked method in BookingController.java

public void createCustomer()
{

    // showMessageInDialog works fine but openDialog doesnt,
    // RequestContext.getCurrentInstance().showMessageInDialog(new FacesMessage(FacesMessage.SEVERITY_INFO,
    // "What we do in life", "Echoes in eternity."));
    Map<String, Object> options = new HashMap<String, Object>();
    options.put("modal", true);
    options.put("draggable", false);
    options.put("resizable", false);
    options.put("contentWidth", 500);
    options.put("contentHeight", 100);
    options.put("includeViewParams", true);
    RequestContext.getCurrentInstance().openDialog("/test",options,null);
    // Tried below also.
    // RequestContext.getCurrentInstance().openDialog("test",options,null);
    // RequestContext.getCurrentInstance().openDialog("/hms/test",options,null);
}

test.xhtml under root webapp folder

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Cars</title>
    <h:outputScript name="jquery/jquery-plugins.js" library="primefaces"/>
    <h:outputScript name="jquery/jquery.js" library="primefaces"/>
</h:head>

<h:body>
    <h:outputText value="Hi" />
</h:body>
</html>

faces-config.xml

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

Regards, Kapil

primefaces 5.1 Mojarra 2.2.8 wildfly-8.2.0.Final


Solution

  • Do you change listener="#{bookingController.createCustomer}" for actionListener="#{bookingController.createCustomer}" ?

    <p:commandLink value="Create Customer">
        <p:ajax event="click" listener="#{bookingController.createCustomer}"/>
    </p:commandLink>
    

    to

    <p:commandLink value="Create Customer" actionListener="#bookingController.createCustomer}">