struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Reumann <>
Subject Re: Radio button for a 3rd level list
Date Tue, 10 May 2005 14:59:32 GMT
Kalyan Ayyagari wrote the following on 5/10/2005 10:47 AM:
> public class Component{
> int id;
> boolean amISelected; }
> My JSP needs to have a radio button for each component. For example, say
> level3List has 3 components, red, green and blue. Then the JSP will have 3
> radio buttons, one for red, one for green and one for blue. Now let's say
> that we have only clicked the radio button for red. Now when we submit the
> form I want the boolean amIselected for red to be true; and false for green
> and blue.

Well, this can be a little tricky or really simple. The first thing I 
need to ask is "What is your business requirement that you are actually 
trying to tackle?" The reason I ask this is, before I get into how you 
can do what you want, their could possibly be a much cleaner solution.

For example, if you want the user to "select" between three components, 
even if selecting between multiple sets of three components (red, green, 
blue). Why not provide radio buttons but for the value simply provide 
the unique componentID for the value ? Then when the form submits you 
have the 'id's of the components the user selected? I think this would 
be a much cleaner solution, however sometimes you do need to do 
something like you are describing, so there are ways.

The tricky part is that name of each radio button would be different 
based on the fact that you are wanting to modify a property of bean in 
the form (not a simple boolean property directly in the form). I think 
you would have to use javascript here. I'd probably go with a checkbox 
for each and although the names would be different for the checkbox, you 
could give them all a similar id based on your iteration. Then when one 
is checked you'd pass in the id of that checkbox and your javascript 
function would know how to turn off the other ones. Again, first step is 
figuring out what exactly you need to capture, because my guess is you 
don't have to go this route.


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

View raw message