Reputation: 271
I get this
javax.servlet.ServletException: BeanUtils.populate: NullPointerException
when I left the page open for a while (about 30 mins) and then clicked on the 'Submit' button on my page. I have seen a couple of posts on Indexing on StackOverflow and Googled and I went through them, trying to understand and implement, but nothing seems to be helping. Here is the error screenshot:
HTTP Status 500 - BeanUtils.populate
type Exception report
message BeanUtils.populate
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:515)
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
FORM (PhaseTrackerForm.java):
private PhaseTrackerSelectApprInfo[] selectApprList;
public PhaseTrackerSelectApprInfo[] getSelectApprList() {
return selectApprList;
}
public void setSelectApprList(PhaseTrackerSelectApprInfo[] selectApprList) {
this.selectApprList = selectApprList;
}
FORM (PhaseTrackerSelectApprInfo):
private String dbName;
private String schemaName;
private String serviceName;
private String action;
private String phase2MoveDate;
private String approverProfileId;
private ArrayList approverList;
public String getDbName() {
return dbName;
}
public void setDbName(String dbName) {
this.dbName = dbName;
}
public ArrayList getApproverList() {
return approverList;
}
public void setApproverList(ArrayList approverList) {
this.approverList = approverList;
}
public String getApproverProfileId() {
return approverProfileId;
}
public void setApproverProfileId(String approverProfileId) {
this.approverProfileId = approverProfileId;
}
public String getSchemaName() {
return schemaName;
}
public void setSchemaName(String schemaName) {
this.schemaName = schemaName;
}
public String getServiceName() {
return serviceName;
}
public void setServiceName(String serviceName) {
this.serviceName = serviceName;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getPhase2MoveDate() {
return phase2MoveDate;
}
public void setPhase2MoveDate(String phase2MoveDate) {
this.phase2MoveDate = phase2MoveDate;
}
JSP Code:
<logic:iterate id="selectApprList" name="phaseTrackerForm" indexId="i" property="selectApprList" type="com.cisco.rdac.info.PhaseTrackerSelectApprInfo">
<bean:define id="myOptions" name="selectApprList" property="approverList" type="java.util.Collection"/>
<tr>
<td >
<bean:write name="selectApprList" property="dbName"/>
</td>
<td >
<bean:write name="selectApprList" property="schemaName"/>
</td>
<td >
<bean:write name="selectApprList" property="serviceName"/>
</td>
<logic:equal name="moveTo" value="phase2" >
<td>
<bean:write name="selectApprList" property="action"/>
</td>
<td>
<logic:empty name="selectApprList" property="phase2MoveDate">
N/A
</logic:empty>
<logic:notEmpty name="selectApprList" property="phase2MoveDate">
<bean:write name="selectApprList" property="phase2MoveDate"/>
</logic:notEmpty>
</td>
</logic:equal>
<td >
<html:select indexed="true" name="selectApprList" property="approverProfileId" style="font-size: 90%;">
<html:options collection="myOptions" property="value" labelProperty="label" />
</html:select>
</td>
</tr>
</logic:iterate>
struts-config.xml mapping:
<action
name="phaseTrackerForm"
path="/phaseTracker"
scope="session"
parameter="methodToCall"
validate="true"
input="/WEB-INF/pages/jsp/phaseTrackerInfoPage.jsp"
type="com.test.actions.PhaseTrackerAction">
<forward name="phaseTrackerRequest" path="/WEB-INF/pages/jsp/phaseTrackerInfoPage.jsp" />
<forward name="phaseTrackerSelectAppr" path="/WEB-INF/pages/jsp/phaseTrackerSelApprPage.jsp" />
<forward name="sameApprover" path="/WEB-INF/pages/jsp/phaseTrackerSelSameApprPage.jsp" />
<forward name="phaseTrackerSubmit" path="/WEB-INF/pages/jsp/phaseTrackerSubmittedPage.jsp" />
</action>
I understood indexing getters and setters but selectApprList
is the id of logic:iterate
tag and a PhaseTrackerSelectApprInfo
array. I think this array type is supposed to work but I get the error anyway. I'm using Struts and work on the maintenance of this code so can't do any major changes.
Upvotes: 1
Views: 10814
Reputation: 1
It doesn't matter that selectApprList is the id of
logic:iteratetag, but it matters that it's a name of
` tag. Looking at your code I didn't find getter for this property and/or getters for the objects it contains.
Similar issue you can find:
The question now is, is the new instance ready to deal with setting values on your ArrayList field? Struts will not instantiate that list for you, it wouldn't know how to. So make sure that when Struts accesses your ActionForm, the ArrayList already exists.
You can find an example how to use <logic:iterate>
tag.
Upvotes: 0