我从网站上的类似问题了解到,为了避免默认值,我必须使用包装类,所以我将我的int更改为Integer,但后来我得到nullpointerexception,我想如果你将一个空值传递给jsf它只是将其显示为空字段。我正在使用glassfish 4.0。我无法理解为什么我会得到这个例外
以下是我得到的例外
javax.el.ELException: /index.xhtml @23,66 value="#{userIdea.idea.empid}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIOutput.getValue(UIOutput.java:174)
at javax.faces.component.UIInput.getValue(UIInput.java:291)
at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:176)
以下是我的jsf代码段
Employee ID:
<h:inputText value="#{userIdea.idea.empid}" required="true"
requiredMessage="You must enter a Employee ID"
converterMessage="Employee ID must be a number" id="empid" />
Idea class snippet
private Integer empid;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
答案 0 :(得分:2)
也将getter更改为Integer。
public Integer getEmpid() {
return empid;
}
否则编译器将失败的autounbox(empid.intValue()
)。
答案 1 :(得分:0)
一些建议: