linechart NPE

UI Components for JSF
Post Reply
ramo.karahasan
Posts: 76
Joined: 18 Apr 2010, 23:57

01 Sep 2010, 21:46

Hi,

i'm trying out the linchart from the showcase to implement by myself....

i'm doing it like in the documentation, but when i start the server and go to my page, i got the following NPE:

Code: Select all

SCHWERWIEGEND: Error Rendering View[/index.xhtml]
java.lang.NullPointerException
	at org.primefaces.component.chart.line.LineChartRenderer.encodeLocalData(LineChartRenderer.java:68)
	at org.primefaces.component.chart.line.LineChartRenderer.encodeScript(LineChartRenderer.java:50)
	at org.primefaces.component.chart.BaseChartRenderer.encodeEnd(BaseChartRenderer.java:54)
	at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
	at java.lang.Thread.run(Thread.java:619)
but why? i thought, the constructor is called when i do something like:

Code: Select all

<p:lineChart value="#{chartBean.births}" var="birth" xfield="#{birth.year}">
or is the getMethod called directly?

i#m using tomcat 6.x and primefaces-2.1

Greetings,
Ramo

callahan
Posts: 768
Joined: 27 May 2010, 22:52

01 Sep 2010, 22:33

Hi,

Line 67 & 68 of LineChartRenderer are:

Code: Select all

Line 67: Collection<?> value = (Collection<?>) chart.getValue();
Line 68: for (Iterator<?> iterator = value.iterator(); iterator.hasNext();) {
so maybe chartBean.births is null.

ramo.karahasan
Posts: 76
Joined: 18 Apr 2010, 23:57

01 Sep 2010, 22:42

Hi,

thank you for the answer. I guess that births is null too, but i'm not sure about the steps that are processed... i thought if i use an expression liek value="#{chartBean....}" than at first the constructor is called and after that the accessor method.

but it seems that i'm wrong with this thoughts.

Am i?

Greetings,
Ramo

callahan
Posts: 768
Joined: 27 May 2010, 22:52

01 Sep 2010, 22:55

No, you're not wrong. If the class corresponding to chartBean is registered as a managed-bean (is it?), then it will be constructed automatically at the appropriate time. Perhaps it is constructed but doesn't initialize the births property.

ramo.karahasan
Posts: 76
Joined: 18 Apr 2010, 23:57

02 Sep 2010, 08:03

Hi,

yes i did:

my bean looks like this:

Code: Select all

package de.match.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class ChartBean {

	private List<Birth> births;

	public ChartBean() {
		births = new ArrayList<Birth>();
		births.add(new Birth(2004, 120, 180));
		births.add(new Birth(2005, 450, 20));
		births.add(new Birth(2006, 22, 149));
		births.add(new Birth(2007, 233, 2344));
	}

	public List<Birth> getBirths() {
		return births;
	}



}
the domainclass like this:

Code: Select all

package de.match.impl;

public class Birth {

	private int year, boys, girls;

	public Birth() {
		// TODO Auto-generated constructor stub
	}


	public Birth(int year, int boys, int girls){
		this.year = year;
		this.boys = boys;
		this.girls = girls;
	}


	public int getYear() {
		return year;
	}


	public int getBoys() {
		return boys;
	}


	public int getGirls() {
		return girls;
	}



}
and my facelet like this:

Code: Select all

...
<p:lineChart value="#{chartBean.births}" var="birth" xfield="#{birth.year}">



</p:lineChart>
...
so that should be exactly the same like in the documentation. I still not know, why i get an NPE..

Thanks for your thoughts,
Ramo

callahan
Posts: 768
Joined: 27 May 2010, 22:52

02 Sep 2010, 10:10

Unfortunately there are two ManagedBean annotation and you've picked the wrong one.
The @ManagedBean annotation in the javax.faces.bean package is the one to use.
The @ManagedBean annotation in the javax.annotation package doesn't work with JSF.

ramo.karahasan
Posts: 76
Joined: 18 Apr 2010, 23:57

02 Sep 2010, 10:23

Hi,

thank you.

i wasn't fully aware of the differences about both beans.

@All

http://weblogs.java.net/blog/cayhorstma ... ad-arrival

Here's an short explanation


Thank you!
Ramo

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 36 guests