tags:

views:

346

answers:

3

This is a Seam application.

HTML

<h:selectManyCheckbox value="#{officeCriteria.carrier}">
    <f:selectItem itemValue="ATT" itemLabel="ATT" />
    <f:selectItem itemValue="VZB" itemLabel="VZB" />
</h:selectManyCheckbox>

backing bean OfficeCriteria:

private List<String> carrier;

public List<String> getCarrier() {
 return carrier;
}

public void setCarrier(List<String> carrier) {
 this.carrier = carrier;
}

When I load the page I get a null pointer exception on carrier. What am I doing wrong?

    2:10,963 ERROR [viewhandler] Error Rendering View[/ONDSearchPage.xhtml]
javax.faces.FacesException: javax.el.ELException: /ONDSearchPage.xhtml @264,81 value="#{officeCriteria.carrier}": Error reading 'carrier' on type dne.nmt.ond.model.OfficeCriteria_$$_javassist_seam_6
    at javax.faces.component.UIOutput.getValue(UIOutput.java:187)
    at com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:593)
    at com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:117)
    ....
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.ELException: /ONDSearchPage.xhtml @264,81 value="#{officeCriteria.carrier}": Error reading 'carrier' on type dne.nmt.ond.model.OfficeCriteria_$$_javassist_seam_6
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:76)
 at javax.faces.component.UIOutput.getValue(UIOutput.java:184)
    ... 95 more
Caused by: java.lang.NullPointerException
    at dne.nmt.ond.model.OfficeCriteria.getCarrier(OfficeCriteria.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    .....
    at org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53)
    at org.jboss.el.parser.AstValue.getValue(AstValue.java:67)
    at org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
    at com.sun.facelets.el.TagValueExpression.getValue(TagValueExpression.java:71)
    ... 96 mor
A: 

What is in OfficeCriteria.java line 108? Something you are referencing there is null, and I guess you aren't expecting it to be.

digitaljoel
What's null is the carrier property. But it's a brand new rendering of a web page so of course it's null. Everything is null. Why does it care in this case that carrier is null? That's really the question. Does this make sense?
can you paste the actual code at line 108? Based on the stack trace, it looks like the NullPointerException is occurring at that line, not within the JSF stuff. I would also have to agree with romaintaz that initializing carrier to an empty array list would be a good idea.
digitaljoel
A: 

What I suggest is that you set an empty list (and not null) for the property carrier:

private List<String> carrier = new ArrayList<String>();

public List<String> getCarrier() {
        return carrier;
}

public void setCarrier(List<String> carrier) {
        this.carrier = carrier;
}
romaintaz
A: 

The answer is that my original code works as it is.

The difficulty (and what I left out) was a debugging statement that referenced an element in the list. Thanks to the person who suggested I actually look at line 108. :-)

And BTW to the person who suggested initializing this with a new List, I had tried that already and got some error (I can't remember what).

Thanks for the help.