jQuery in Action, 3rd edition
The moose likes Struts and the fly likes select a radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "select a radio button" Watch "select a radio button" New topic

select a radio button


Joined: May 04, 2005
Posts: 28
Can someone tell what is the correct way to select one radio button when displaying a response to the client in struts based JSP page.

Tried following with checked attribute does not work

<logic:match name="<%=sessionValue%>" property="type" value="C">
<html:radio checked="checked" name="<%=sessionValue%>" property="type" value="I"/>Internal

Thanks<br />Marie
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since the html:radio tag automatically checks or unchecks the radio button based on the value of the "type" property in your ActionForm, the solution is to set the value of the "type" property prior to forwarding to the JSP.

So, in the Action that forwards to this jsp you will code:


and in your JSP you will code:

<html:radio property="type" value="I"/>

If you do this, Struts will automatically cause this button to display as checked.

Consultant, Sima Solutions

Joined: May 04, 2005
Posts: 28
I have the setter setType in the action class, It displays on the WAS console too. But it does not set to the correct value taken from the DB.

I need a <logic:match done correctly. I think the logic tag attributes are wrong.

<logic:match name="<%=sessionValue%>" property="type" value="E"> ---???
<html:radio name="<%=sessionValue%>" property="type" value="I"/>Internal
<html:radio name="<%=sessionValue%>" property="type" value="E"/>External
Pratik Shah

Joined: Dec 19, 2005
Posts: 2
can you be more clear with what you exactly expect your code to do..
as in while displaying the response which specific radio button do you want to be selected
for e.g: you want every time the first radio button to be selected and so on..
I agree. Here's the link: http://aspose.com/file-tools
subject: select a radio button
It's not a secret anymore!