0

I'm using WebSphere 5.1.2 and think it's Struts 1, but I'm not sure.

My problem is the following.

I have in my form a Dynamic List of a bean BeanName, with inputs type text.

My form is something like this (can't copy&paste because it's on a Virtual Machine without Internet):

public class MyForm extends ActionForm implements Serializable {
    // Property
    private List beanNameList = new ArrayList();

    // Simple Getter
    public List getBeanNameList() {
        if (beanNameList == null) {
            beanNameList = new ArrayList();
        }
        return beanNameList ;
    }

    // Item Getter
    public BeanName getBeanNameList(int index) {
        if (beanNameList == null) {
            beanNameList = new ArrayList();
        }
        for (int i = beanNameList.size(); i <= index; i++) {
            beanNameList.add(new BeanName());
        }
        return (BeanName)contractList.get(index);
    }

    // Simple Setter
    public List setBeanNameList(List value) {
        return beanNameList = value;
    }

    // Item Setter
    public BeanName getBeanNameList(int index, BeanName value) {
        if (beanNameList == null) {
            beanNameList = new ArrayList();
        }
        for (int i = beanNameList.size(); i <= index; i++) {
            beanNameList.add(new BeanName());
        }
        contractList.set(index, value);
    }
}

When I submit the form, I receive an IndexOutOfBoundsException: index: 3, size: 0.

Analizing the console, I realized Struts is using ArrayList.get, and not getBeanNameList, as you may see in the image:

console error

Any ideas?

Ed de Almeida
  • 3,675
  • 4
  • 25
  • 57
  • It seems you are getting a range error. I suggest you to check these **for** you have there. They are all great candidates to be the cause of your error. A checkpoint and some debugging will surely help you find the error. – Ed de Almeida Aug 06 '16 at 02:25
  • Thanks for Replly ed, but this is the problem. Even if i set a break point there, it don't stops. – Jhoni Carlos Aug 06 '16 at 02:44
  • I put the breakpoint on List getter "getBeanNameList()", and it stops, but didn't on Simple getter "public BeanName getBeanNameList(int index)" – Jhoni Carlos Aug 06 '16 at 02:52

1 Answers1

1

I found the problem...

My version of Struts is too old, and it realy don't use the getter and setter with index on siganture, it's using ArrayList.get, or something like that.

To solve the problem, i have created a hidden field with the size of my list, and on the reset method of the form, i just setup the size of the list.