views:

976

answers:

4

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?

A: 

Is it even making it to the Action? I suggest using an HTTP listener like Fiddler, or IBM Page Detailer, so that you can see what, if anything, is even being sent to the server.

meiguoren
A: 

Please consider a debug statement in your action to see what you get back. I'm thinking something like at the top of your Action:

Enumeration parameterNames = request.getParameterNames();
while (parameterNames.hasMoreElements()) {
  String currentParameterName = (String) parameterNames.nextElement();
  String[] values = request.getParameterValues(currentParameterName);
  for (String value : values) {
    logger.debug("Parameter " + currentParameterName + " has value " + value);
  } 
}

And I think it would be better if you use the real HTML in your sample. The " + i + " thing is not HTML and I can't see from here how that is rendered to HTML. It's probably allright but I prefer to see the HTML code as the browser sees it.

extraneon
h lol. that was my problem. I forgot to change " + i + " to \"" + i + "\"
+1  A: 

Hi,

you should use the s:select tag. see http://struts.apache.org/2.1.6/docs/select.html

best regards, Jan

Jan
A: 

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.

Eric Rank