File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts html:radio Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts html:radio Question" Watch "Struts html:radio Question" New topic

Struts html:radio Question

Howard Thompson

Joined: Nov 06, 2002
Posts: 4
My problem is setting up an initial value for a Radio field using Struts. In plain old HTML you could do something by adding a "checked" key word. With Struts there doesn't seem to be any "Checked" option.
With a "Select" I believe I can just assign "Value" to have my initial value; as read previously from a database (in the example its from the bean "account.") I believd this works ok.
<td width="49%">Security Question</td>
<td width="43%">
<html:select property="securityQuestion" value="<%=account.getSecurityQuestionType() %>">
<html ptions collection="securityquestions" property="questionText" />
The problem is with Radio buttons. From everything I've read, I either that have to :
a) Set the form field value to whatever is desired and it will show up correctly. But my problem with this is that I don't see how to set it initially based on a session/request bean. I tried looking at the form "reset" method, checking for "" as an initial value and then setting it to the desired session bean value. But, my reset method wasn't being called by default. I obviously can't use my Perform Action method.
b) I've seen some servlet code that spits out real html. I'd like to solve this using Struts taglib.
<td width="49%">Type of Account:</td>
<td width="43%">
<logic:iterate id="t" name="accounttypeset" type="java.lang.String">
<html:radio property="accountType" value="<%=t %>"/>
<%=t %>
Any thoughts out there?
I'm still a bit green in the Java/Stuts/JSP world but I've done a fair bit of hunting.
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
Your form's reset method is called at the start of every request. Try putting some logging in there to prove it.
However the reset is called BEFORE struts initialises all the form fields to the values from the request. So if you have the value in your request, then it will be entered in that field.
It's not clear exactly how you determine what its initial value should be - you mention session/request beans. There are struts-standard methods for doing this that the struts designers decided upon, but how to apply them depends on what you want to achieve.

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
I agree. Here's the link:
subject: Struts html:radio Question
It's not a secret anymore!