• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

preselect a radio button

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I would like to know as to how i can preselect the topmost radio button from a list of buttons in Struts using the struts tags.

Cheers,
Ashwin
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, hope this solves ur problem....

say you have the following radio buttons


Its possible to pre-select any radio button by specifying a default value for the property on the actioon form associated with the radio button. The property setter method must be called from the constructor and the reset method. Note that it should not be called from the reset method if the bean is in session scope because the selections will be reset for each page.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if the form is in session scope, setting the value in the reset() method should be OK since Struts calls the reset() method prior to calling the setters on the bean. The reset() method will set it to the default value, and then setSelected() will set it to the value entered by the user.

If you don't want to set default values in the ActionForm, you can just set the value in the Action class that forwards to the JSP.
 
dnyan ginde
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the correction.
 
Christian Nash
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

But i will not like to hard code the values either in the Action form or the jsp page. Is there a wy to do this preselection dynamically

your code said that
code:
--------------------------------------------------------------------------------

<html:radio property="selected" value="One">One</html:radio><html:radio property="selected" value="Two">Two</html:radio><html:radio property="selected" value="Three">Three</html:radio>

--------------------------------------------------------------------------------




public class MyActionForm extends ActionForm{ private String selected; public MyActionForm() { setSelected("One"); } public void reset( ActionMapping mapping, HttpServletRequest request ) { setSelected("One"); } public String getSelected() { return this.selected; } public void setSelected( String selected ) { this.selected = selected; }}

Thanks and Cheers,
Ashwin
 
dnyan ginde
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to do this dynamically then you can have the values of your radio buttons mapped to a bean.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic