• 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

Struts 1.1: html:radio issues

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

I am facing issues with struts html:radio tag. I need default radio button checked, not lose them when validation fails and also handle related form fields depending upon the radio button value selected - implemented using a multi-page form.
I was having a look at the past postings on this forum and i found some help - https://coderanch.com/t/54565/Struts/html-radio

As per suggested, i have done the below:

1. struts-config.xml: in action tag, added name attribute with value corresponding to my formbean.

2. In Action class, when my jsp page is invoked via the *.do (note that the previous invoking jsp does not correspond to my formbean. For my functionality, i have a different formbean as compared to the formbean of the invoking jsp), in the execute method i have retrieved MyForm from the ActionForm and explicitly set the default value on the radio button (setter).

Now: When my jsp is finally displayed, it shows the 2 radio buttons with one of them checked as the default value (as set in my Action Class).

Based on the radio button checked, other fields on my form (jsp) are being displayed. This goes for a toss when validation fails.
e.g. I have 2 radio buttons - Yes and No. When No is checked (default), 2 other text fields (firstName and lastName) should not be displayed. When Yes is checked, then the 2 text fields (firstName and lastName) should be displayed. Now since I have handled default radio button selection through the Action class, my jsp page shows 'No' radio button as selected and therefore firstName and lastName are not displayed through the use of javascript - which is correct. When user explicitly selects 'Yes' radio button, firstName and lastName are now displayed through the use of javascript - which is correct. But if i leave some other fields empty, then validation in my ActionForm fails and my jsp page is displayed with the error messages. The last selected radio button is also displayed with the correct value ('Yes'). But firstName and lastName text fields which should have been displayed for 'Yes' are now not visible on the page. (as though 'No' radio button was selected.
Is this issue related to Struts ?? and how can i handle it ?? I am sure there is no issue in Javascript, since i have checked and tested the toggle functionality of the firstName and lastName with 'Yes' and 'No' radio buttons by itself (not using struts).

I am keeping the form in session scope (struts-config.xml). I do not have reset method implemented. I did try and add the reset method and in that method, i set the radio button value to empty String (""), but this did not work (no radio button was selected when the jsp page was displayed he first time).

Let me know if any other information is required.

Any help would be be greatly appreciated as i have struggled with this the entire day..


Thanks in advance,
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd suggest you call JavaScript code from the onload event of the body tag to hide or display the fields based on the value of the radio buttons.
 
lavi mendonca
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill.. I incorporated your advice and its working now..

Thanks once again!!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic