struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kevin J. Turner" <>
Subject Multiple checkboxes with the same name -- possible with Struts?
Date Thu, 28 Feb 2002 16:32:58 GMT
Is it possible, using the Struts framework, to have multiple checkboxes
that are named the same but have different values?
First, a little background on this:

Say you have the following four fruity checkboxes on a form, with Apple
and Mango checked:
[x] Apple
[ ] Kiwi
[x] Mango
[ ] Banana
Each checkbox has the same html *name* property of "fruit", but they all
have different html "value" properties (Apple, Kiwi, etc).
In order to get those from the request you would need to do something
like this:
String[] fruit = request.getParameterValues("fruit");
If you just do a request.getParameter("fruit") with the above scenario,
then you'll only get one string back, "Apple" (because its the first one
So the problem is, where Struts is concerned, is this: Request-scoped
Form beans, behind the scenes, do a request.getParameter() to set the
bean values, correct? But when there are multiple form fields with the
same name, the getParameter() won't do, Struts needs to call
request.getParameterValues(). I'm assuming its not smart enough to do
this? (Or is it doing this and I'm just doing something wrong?)
To counter this problem, in my Action classes associated with the form
bean, I grab values from the request object using getParameterValues(),
and store them into a String array. Then I call my setter method,
passing in the array. In other words, I call the setter manually, not
automatically by Struts.
Is there another workaround for this or is this my only option?

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message