我有一个简单的问题,当我调用一个托管bean方法返回一个列表时,为什么总是得到一个NPE。我在我看来使用了primefaces向导组件。例如可以sometone告诉我,这两者之间的区别:调用托管bean方法返回一个NPE
不起作用:
public List<RequiredParam> getRequiredFields() {
if(!this.sdeCommand.getActions().isEmpty() &&this.action!=null &&!this.action.equals("")){
for(CommandAction act:this.sdeCommand.getCommandActions()){
if(act.getActionName().equalsIgnoreCase(this.action)){
this.requiredFields.addAll(act.getFields());
}
}
}
return this.requiredFields;
}
但是这个工程:
public List<RequiredParam> getRequiredFields() {
return this.requiredFields;
}
的观点:
<c:forEach items="${gdsiGeodataBean.requiredFields}" var="reqs">
<h:outputLabel for="#{reqs.name}" value="#{reqs.name}:* " />
</c:forEach>
错误信息:
java.lang.NullPointerException
com.tsystems.appbeans.GdsiGeodataBean.getRequiredFields(GdsiGeodataBean.java:103)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
org.apache.el.parser.AstValue.getValue(AstValue.java:118)
...
我的观点:
显然,你的一些bean的属性是'null'。仔细检查你是否已经正确实例化了所有的'List'属性 – 2012-01-05 11:38:14
@ Mr.J4mes,谢谢其中的一个属性为null。我正在使用一个向导,并且已经在前一个选项卡中设置了该属性。不知何故该物业失去了价值。 – algone 2012-01-05 17:15:24