我從網站上的類似問題了解到,爲了避免默認值我不得不使用包裝類,所以我改變我的整數爲整數,但後來我得到nullpointerexception,我想如果你傳遞一個null值給jsf,它只會顯示它爲空字段。我正在使用glassfish 4.0。我無法理解爲什麼我收到此異常避免默認的int值0顯示在h:inputText
以下是例外,我正在逐漸
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" />
理念類片斷
private Integer empid;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
與它有什麼關係? –