5
I’m developing a web app that aims to work like Facebook. During the navigation 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 (central content) page contains pe:masterDetail it causes an error on the server
That is the mistake:
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 via F5 to page, the central content loads right, without causing error.
What I checked via Debug is that Breadcrumb is null the first time you run updateBreadcrumb(), and is valued when you reload the page.
But I don’t want to reload the page. How to proceed so that it works in case the page fragment is loaded via AJAX?
I used both cases, and the error persists...
– Alexandre De Carli
I edited my answer, take a look there, and put an example. If you take a look at the Primefaces documentation the components should always stay inside a form to function properly. The Primefaces Extension is no different, try to put the
pe:masterDetail
within a form also.– brunowff
I have other pages that work with AJAX as well, but when you have the component pe:Masterdetail does not work, returning the error that is in the question.
– Alexandre De Carli
But you got to put the components
pe:MasterDetail
within theform
?– brunowff
I did a little different... The solution posted as answer to the question... Thanks anyway @brunowff
– Alexandre De Carli