3

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?

Joe
  • 7,749
  • 19
  • 60
  • 110
wjr
  • 324
  • 1
  • 3
  • 14
  • I dont' see dialog code in any of your posted xhtml file. – Makky Feb 03 '14 at 16:28
  • 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 Feb 03 '14 at 16:35
  • whats harming you using standard primaces dialog – Makky Feb 03 '14 at 19:15

2 Answers2

11

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>
  • I notice that you are using version 2.2. In my config file, it's showing up as 2.1. In a rash act, I simply copied your header to my file, thus demonstrating the value of subversion's "revert modifications" option. So, do you know if this feature is dependent upon 2.2? – wjr Feb 03 '14 at 21:50
  • I believe it will work fine on 2.1. The part is what really matters. Have you done any test coping only that part? – Daniel Teleginski Camargo Feb 03 '14 at 23:01
  • No, I typed that in by hand since user's guide is pdf and isn't set up to allow copying that. I'll try just copying that part although I believe that it is correct. – wjr Feb 03 '14 at 23:32
  • @Daniel Camargo :- is your dialog.xhtml inside WEB-INF folder – Subodh Bisht Feb 20 '15 at 07:43
  • Just to confirm that this works. I am using Primefaces 5.3 and the pop was not coming up. This solved it. – Tirath Sep 27 '16 at 13:53
1

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>
FloatOverflow
  • 791
  • 9
  • 9