Multiple checkboxes with the same name -- possible with Struts?
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 selected). 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Multiple checkboxes with the same name -- possible with Struts?
Look at the html:multibox tag. David Gaulin Tel / tél :(613) 946-9595 Email / courriel : [EMAIL PROTECTED] Facsimile / télécopieur : (613) 954-6012 Industry Canada | 235 Queen Street, Ottawa, Ontario, K1A 0H5 Industry Canada | 235, rue Queen, Ottawa (Ontario) K1A 0H5 -Original Message- From: Kevin J. Turner [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 12:30 PM To: Struts Users Mailing List Subject: Multiple checkboxes with the same name -- possible with Struts? 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 selected). 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Multiple checkboxes with the same name -- possible with Struts?
Alas, that deoesn't solve the problem. Look at the html:multibox tag. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Multiple checkboxes with the same name -- possible with Struts?
I am not sure to understand your problem then. In my case we have roles instead of fruit. We have an activity that have more then one participant and each participant can have more then one role. [X]Organizer [ ]Speaker [ ]Attendee [ ]Sponsor ... etc My ActionForm contains a participant bean that has a role property define as String[] role; The array of string gets populated properly with the option checked. Sorry if this is not what you are looking for, it just seems really similar. David Gaulin Tel / tél :(613) 946-9595 Email / courriel : [EMAIL PROTECTED] Facsimile / télécopieur : (613) 954-6012 Industry Canada | 235 Queen Street, Ottawa, Ontario, K1A 0H5 Industry Canada | 235, rue Queen, Ottawa (Ontario) K1A 0H5 -Original Message- From: Kevin J. Turner [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 12:48 PM To: 'Struts Users Mailing List' Subject: RE: Multiple checkboxes with the same name -- possible with Struts? Alas, that deoesn't solve the problem. Look at the html:multibox tag. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Multiple checkboxes with the same name -- possible with Struts?
My HTML looks like this input type=checkbox id=Exhibitor1 name=participants[0].roleCd value=E input type=checkbox id=Speaker1 name=participants[0].roleCd value=S input type=checkbox id=Attendee1 name=participants[0].roleCd value=A input type=checkbox id=Head1 name=participants[0].roleCd value=H the participants[0] is caused by the fact that I have more then one participants per activity but tif you put input type=checkbox name=fruit value=apple input type=checkbox name=fruit value=blueberry input type=checkbox name=fruit value=Strawberry and you have a String[] fruit; in your action form. It is my understanding that this would work. Anyway this is working for me. David Gaulin Tel / tél :(613) 946-9595 Email / courriel : [EMAIL PROTECTED] Facsimile / télécopieur : (613) 954-6012 Industry Canada | 235 Queen Street, Ottawa, Ontario, K1A 0H5 Industry Canada | 235, rue Queen, Ottawa (Ontario) K1A 0H5 -Original Message- From: Kevin J. Turner [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 1:09 PM To: 'Struts Users Mailing List' Subject: RE: Multiple checkboxes with the same name -- possible with Struts? It does seem really similar. When you view the html source, does each checkbox have the same name property? Also, to add to the complexity, in my particular case, the list of checkboxes is dynamically generated via the logic:iterate tag. It is not kwown ahead of time how many checkboxes there will be. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 1:02 PM To: [EMAIL PROTECTED] Subject: RE: Multiple checkboxes with the same name -- possible with Struts? I am not sure to understand your problem then. In my case we have roles instead of fruit. We have an activity that have more then one participant and each participant can have more then one role. [X]Organizer [ ]Speaker [ ]Attendee [ ]Sponsor ... etc My ActionForm contains a participant bean that has a role property define as String[] role; The array of string gets populated properly with the option checked. Sorry if this is not what you are looking for, it just seems really similar. -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Multiple checkboxes with the same name -- possible with Struts?
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 selected). 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: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: Multiple checkboxes with the same name -- possible with Struts?
I'm assuming its not smart enough to do this? Nope. Struts is smart enough to do this. If you use the multibox tag as David Gaulin suggested and your bean looks like public void setFruit( String[] fruits ) {...} public String[] getFruit() {...} Then all your multiboxes look like html:multibox property=fruit value=kiwi / and so on. Your bean will be automatically populated with an array of all the selected fruits. So in your example [x] Apple [ ] Kiwi [x] Mango [ ] Banana getFruit() in your action would return an array containg the strings Apple Mango Are you trying this and it's not working? -Jonathan -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Multiple checkboxes with the same name -- possible with Struts?
I will try again.. there must be something I'm not doing right Thx. -Original Message- From: Jonathan James [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 28, 2002 2:16 PM To: Struts Users Mailing List; [EMAIL PROTECTED] Subject: Re: Multiple checkboxes with the same name -- possible with Struts? I'm assuming its not smart enough to do this? Nope. Struts is smart enough to do this. If you use the multibox tag as David Gaulin suggested and your bean looks like public void setFruit( String[] fruits ) {...} public String[] getFruit() {...} Then all your multiboxes look like html:multibox property=fruit value=kiwi / and so on. Your bean will be automatically populated with an array of all the selected fruits. So in your example [x] Apple [ ] Kiwi [x] Mango [ ] Banana getFruit() in your action would return an array containg the strings Apple Mango Are you trying this and it's not working? -Jonathan -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]