• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts - Default radio value

 
Marcellus Tryk
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Marcellus Tryk
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Adam, I'll give it a try.
Mars
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic