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
What is in OfficeCriteria.java line 108? Something you are referencing there is null, and I guess you aren't expecting it to be.
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;
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.