Reputation: 21
I've CoverageInfoVO type array in my Action class and want to send value from jsp to action class, but it's not getting mapped. Instead of array If I switch to ArrayList it's working fine. My doubt is, can't we pass array from jsp to Action in struts2 ? I've added code snippet for better illustration.
JSP
<input type="text" name="coverageInfoList[0].month">
Action
public class MyAction {
private CoverageInfoVO[] coverageInfoList;
public CoverageInfoVO[] getCoverageInfoList() {
return coverageInfoList;
}
public void setCoverageInfoList(CoverageInfoVO[] coverageInfoList) {
this.coverageInfoList = coverageInfoList;
}
........
}
CoverageInfoVO
public class CoverageInfoVO {
private String month;
private String enrollmentPremium;
private String secondLowestCostSilverPlanPremium;
private String advancePaymentOfPremiumTaxCredit;
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
...................
}
Upvotes: 1
Views: 133
Reputation: 21
Finally, I'm able to figure out the reason behind the jsp values not being mapped into the Object Array. The cause is CoverageInfoVO is not getting initialised inside the array automatically, so it needs to be initialised manually inside the constructor and then value would be mapped automatically.
Ex.
public MyAction(){
this.coverageInfoList = new CoverageInfoVO[13];
for (int i = 0; i < coverageInfoList.length; i++)
this.coverageInfoList[i] = new CoverageInfoVO();
}
Upvotes: 1