I'm developing a web application that aims to work like Facebook. During browsing the page is not reloaded, loading via AJAX only the central content.
I'm using PrimeFaces 4.0 and PrimeFaces Extension 1.2.1
But when my page (from the central content) contains pe: masterDetail it causes an error on the server
The error is this:
Severe: Error Rendering View[/index.xhtml]
java.lang.NullPointerException
at org.primefaces.extensions.component.masterdetail.MasterDetailRenderer.getMenuItemByLevel(MasterDetailRenderer.java:284)
at org.primefaces.extensions.component.masterdetail.MasterDetailRenderer.updateBreadcrumb(MasterDetailRenderer.java:208)
at org.primefaces.extensions.component.masterdetail.MasterDetailRenderer.renderBreadcrumb(MasterDetailRenderer.java:186)
at org.primefaces.extensions.component.masterdetail.MasterDetailRenderer.encodeMarkup(MasterDetailRenderer.java:138)
at org.primefaces.extensions.component.masterdetail.MasterDetailRenderer.encodeEnd(MasterDetailRenderer.java:101)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:919)
I created a simple page to simulate the error that happens in my application:
Index.xhtml:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Test</title>
</h:head>
<h:body >
<h:form>
<p:commandButton action="#{theBean.goToPage('masterDetailPage.xhtml')}" update=":centerContent"/>
</h:form>
<h:form id="centerContent">
<ui:include src="#{theBean.page}"/>
</h:form>
</h:body>
</html>
TheBean.java:
package br.edu.utfpr.projetoteste;
import java.io.IOException;
import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class TheBean implements Serializable {
private static final long serialVersionUID = 1L;
String page = "test.xhtml"; //Simple blank page for this test
public TheBean() {
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public void goToPage(String page) throws IOException {
this.setPage(page);
}
}
masterDetailPage.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:pe="http://primefaces.org/ui/extensions">
<pe:masterDetail id="masterDetail" >
<pe:masterDetailLevel level="1" levelLabel="Master">
Test
</pe:masterDetailLevel >
<pe:masterDetailLevel level="2" levelLabel="Detail">
Test
</pe:masterDetailLevel>
</pe:masterDetail>
</ui:composition>
When I reload the page via F5, the central content loads right without causing an error.
What I checked out via Debug is that BreadCrumb gets null the first time it runs updateBreadcrumb (), and gets value when it reloads the page.
But I do not want to reload the page. How do I make it work if the page fragment is loaded via AJAX?