This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts - Default radio value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts - Default radio value" Watch "Struts - Default radio value" New topic

Struts - Default radio value

Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Hi all -
I have a list of items in a JSP. An item can be selected by clicking its radio button. The value of each radion button is the id of its associated item. How can I have the first item pre-selected on initial display of the JSP?
An example in Mastering Jakarta Struts suggests that I need to set the property in the associated ActionForm. Is the ActionForm available at this point? How do I get it? Is this the best way to do this? In general how do you (dynamically) set defaults for html controls in Struts?
Thanks in advance,
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 567
You would set the property in the action form, which is available to the jsp when you configure the struts-config.xml properly and use the formbean in the jsp via a html:form tag.
The examples should show you how to do the xml and the tag.
I would use the Action to set the radio property's default value. In the Action you can determine whether the jsp is being called for the first time (and so set the default) or whether it's being called again due to validation failure etc. (in which case you would want to leave the radio property in the formbean, which would be just how the user submitted it).

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.
Marcellus Tryk
Ranch Hand

Joined: May 31, 2001
Posts: 64
Thanks Adam, I'll give it a try.
I agree. Here's the link:
subject: Struts - Default radio value
It's not a secret anymore!