aspose file tools*
The moose likes Struts and the fly likes Struts 1.1: html:radio issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts 1.1: html:radio issues" Watch "Struts 1.1: html:radio issues" New topic
Author

Struts 1.1: html:radio issues

lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
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 - http://www.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,
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Thanks Merrill.. I incorporated your advice and its working now..

Thanks once again!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts 1.1: html:radio issues