Struts2: reading an array of input into an action

inputstruts2text

I'm trying to get an array of input into my action class but it always returns null;

Here's the HTML for the input

<input class="activityInput" type="text" name="sentdate[" + i + "]" value="1" />
<input class="activityInput" type="text" name="sentdate[" + i + "]" value="2" />

and here's the class for the action

public class ActivityAction extends ActionSupport{
    private List sentdate;
    public List getSentdate() {
    return sentdate;
    }

    public void setSentdate(List sentdate) {
        this.sentdate = sentdate;
    }
}

What am i doing wrong?

Best Solution

You shouldn't need the square brackets.

<s:textfield name"sentdate" value="1" />
<s:textfield name"sentdate" value="2" />

would render the following html

<input type="text" name="sentdate" value="1" />
<input type="text" name="sentdate" value="2" />

This should populate the 'sentdate' List of your Action.

Related Question