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?
You must add to the header of your page this line:
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:
I made it work with this code:
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: