1

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;
    }

    ...................
}
0

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.