Nidheesh
Nidheesh

Reputation: 4562

java.lang.NullPointerException at java.io.PrintWriter.write

While running an application with PrimeFaces' <p:wizard> component, I am getting following error:

java.lang.NullPointerException
    at java.io.PrintWriter.write(PrintWriter.java:473)
    at com.sun.faces.application.view.WriteBehindStateWriter.write(WriteBehindStateWriter.java:127)
    at com.sun.faces.renderkit.html_basic.HtmlResponseWriter.write(HtmlResponseWriter.java:666)
    at org.primefaces.component.wizard.WizardRenderer.encodeStepStatus(WizardRenderer.java:236)
    at org.primefaces.component.wizard.WizardRenderer.encodeMarkup(WizardRenderer.java:158)

How is this caused and how can I solve this?

Upvotes: 3

Views: 1578

Answers (1)

BalusC
BalusC

Reputation: 1109112

You're apparently using PrimeFaces 3.0 which is still in non-final stage. This one is clearly a bug in PrimeFaces. You need to report it to the PF guys so that they can fix it.

I've myself also regularly seen this silly exception when an apparent mandatory attribute was missing from some PrimeFaces 3.0 component. For example,

<p:selectOneMenu>
  <f:selectItem itemValue="foo" />
</p:selectOneMenu>

The above works perfectly fine with <h:selectOneMenu>. The item value is been used as both the value and label of the component. That's also how the <f:selectItem> is been specified to work. But yet, the PrimeFaces <p:selectOneMenu> expects the itemLabel attribute to be always present for some reason and passes the null attribute value without checking beforehand straight to the response writer, which in turn throws a completely confusing NullPointerException, exactly the one which you got. Adding the itemLabel attribute solves it:

<p:selectOneMenu>
  <f:selectItem itemValue="foo" itemLabel="foo" />
</p:selectOneMenu>

I am not aware of any similar issues in <p:wizard> (I've never used it), but you might want to try to copy the code of the showcase example 1:1 and then build further based on that, instead of creating one from scratch without any guidelines.

Upvotes: 2

Related Questions