3
votes

I'm trying to use primefaces dialog framework to simplify my code. I've followed the example in the primefaces 4.0 user guide and it's not working.

I copied the example pretty much verbatim creating three files: a file with the dialog in it, a file that calls the dialog and a backing bean file.

The dialog file is named "dialog.xhtml", is in the "/Test" folder and contains:

<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:head>
    <h:body>
        Test dialog
    </h:body>
</html>

The base file is named "testDialog.xhtml", is in the "/Test" folder and contains:

<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>Test Dialog</title>
        <meta name="viewport" content="width=device-width"/>
    </h:head>
    <h:body>
        <h:form>
        <p:commandButton value="View Cars" actionListener="#{hostBean.view}" />
        </h:form>
    </h:body>
</html>

Finally, the backing bean contains:

@ManagedBean
@SessionScoped
public class HostBean implements Serializable {

    public void view() {
        RequestContext.getCurrentInstance().openDialog("/Test/dialog");
    }
}

When I debug it, view gets called but the dialog is not opened. (I have added the three lines to faces-context.)

Any ideas?

2
I dont' see dialog code in any of your posted xhtml file.Makky
From my reading of the user's guide, that's the point of the dialog framework. You can open any xhtml file in a dialog using the framework just by specifying its name.wjr
whats harming you using standard primaces dialogMakky

2 Answers

10
votes

I made it work with this code:

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.context.RequestContext;

@ManagedBean
@ViewScoped
public class HostBean implements Serializable {

    public void view() {
        RequestContext.getCurrentInstance().openDialog("dialog");
    }
}

As both xhtml files are in the same folder (Test) you don't need to use "/Test/dialog" (you can make it more "global" if you use the whole path though).

Don't forget to add this to your faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2"
              xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">

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

</faces-config>
1
votes

You must add to the header of your page this line:

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

Don't worry - do not copy any files to your project - above line is enough because PrimeFaces automatically adds js file.

As you realized you must also add few lines to your faces-config.xml file:

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