views:

637

answers:

2

I have a jsp page with two radio tags.

The page contains a struts2 form. When I submit the form one of two radio must be automatically checked.

Is it possible to do that?

+1  A: 

One of the features of a radio input is that an item in a radio set once selected cannot be deselected except by another member of the set being selected (unlike a checkbox "set"). i.e. if you initialise the page with a selection you can guarantee you will have a value. Does a default value exist you can do this for? Then you can just set checked="checked" on that item.

Alternatively you'll just have to add another validation rule in JS and/or the server side.

annakata
A: 

I believe that with:

<html:radio property="foo" value="yes"/>

this radio tag will show selected (by default) if the method getFoo() of the form-bean returns the string "yes".

May be you can use that to link your form submit to your radio tags ?

VonC