aspose file tools*
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 Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts - Default radio value" Watch "Struts - Default radio value" New topic
Author

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,
Mars
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 565
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).
Adam


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.
Mars
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts - Default radio value
 
Similar Threads
Radio button
Struts 1.1: html:radio issues
How to set default value for a radio button?
defaulting " SelectOne Radio"
Prepopulating Radio buttons in JSP