Passing Multiple Parameters into Action class

Hi everyone, I have a problem passing in multiple parameters into my action class for processing.

<html:formaction="/AddUriPolicy.do" method="GET">

<table border="1">

<tr>

<td>Policy Name</td>

<td><html:text property="polyname"/></td>

</tr>

<tr>

<td>UriSet Name</td>

<td>Rate</td>

<td>Type</td>

<td>QueryAuth</td>

<td>Usage</td>

</tr>

<logic:present name="ratelist">

<logic:iterate name="ratelist">

<tr>

<td><bean:write name="ratelist"/></td>

<td><html:text property="polyrate"/></td>

<td>

<html:select property="polyratetype">

<html:option value="browse">browse</html:option>

<html:option value="event">event</html:option>

<html:option value="time">time</html:option>

</html:select>

</td>

<td>

<html:select property="polyrateauth">

<html:option value="Enable">Enable</html:option>

<html:option value="Disable">Disable</html:option>

</html:select>

</td>

<td>

<html:checkbox property="polyratechecked">

</html:checkbox>

</td>

</tr>

</logic:iterate>

</logic:present>

</table>

<input type="submit" name="Submit" value="Add More">

<input type="reset" name="Reset" value="Reset">

</html:form>

The problem I have is that I need to pair the user's input by row. How can I pass the parameters from my jsp page so when in my Action class, I can request.getParameterValues and get the 5 values of each row separately?

I also populate one of the columns from

<logic:iterate name="ratelist">

<td><bean:write name="ratelist"/></td>

Rather than printing the text out, how can I autofill a textbox with this value?

I would appreciate any suggestions, thanks!

James

[2779 byte] By [homerpsua] at [2007-11-26 15:27:46]
# 1

Just to summarize, I have a table that consists of 5 columns. The number of rows change depending on a list that gets passed into the jsp page. When the user presses the submit button, I need to pair the input by the row it is in. How can I setup my jsp so that my Action class can retrieve and distinguish those row input?

homerpsua at 2007-7-8 21:43:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If you're using struts, you should take advantage of the framework, and let it do all the hard work.

What you want to use are struts indexed properties.

http://struts.apache.org/1.2.9/faqs/indexedprops.html

What you probably want is a nested indexed property.

Create a bean to store ONE record - ie with name, rate, type etc

On your formbean have an array/collection of these (array is probably easier)

// Bean

public class URIPolicy{

String name;

String polyrate;

String polyratetype;

String polyrateauth;

// plus getters/setters

}

// formbean

public class URIPolicyForm extends ActionForm{

URIPolicy[] ratelist;

public URIPolicy getRatelist(int i){

return ratelist[i];

}

public void setRatelist(int i, URIPolicy policy){

ratelist[i] = policy;

}

And then in your JSP, use it as an nested indexed attribute

Where previously you had <html:text property="polyrate"/>

You now need

<html:text name="ratelist" property="polyrate" indexed="true"/>

This should autoname/number the fields something like

<input type="text" name="ratelist.polyrate">, and will automagically populate into the action form.

<html:formaction="/AddUriPolicy.do">

<logic:present name="ratelist">

<logic:iterate name="ratelist">

<tr>

<td><bean:write name="ratelist"/></td>

<td><html:text name="ratelist" property="polyrate" indexed="true"/></td>

<td>

<html:select name="ratelist" property="polyratetype" indexed="true">

<html:option value="browse">browse</html:option>

<html:option value="event">event</html:option>

<html:option value="time">time</html:option>

</html:select>

</td>

<td>

<html:select name="ratelist" property="polyrateauth" indexed="true">

<html:option value="Enable">Enable</html:option>

<html:option value="Disable">Disable</html:option>

</html:select>

</td>

<td>

<html:checkbox name="ratelist" property="polyratechecked" indexed="true">

</html:checkbox>

</td>

</tr>

</logic:iterate>

disclaimer: none of the above code is tested at all, but it should give you the idea. Post back if you have troubles.

evnafetsa at 2007-7-8 21:43:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
thanks evnafets, i'll send u a duke star when I find out how to!
homerpsua at 2007-7-8 21:43:43 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...