| Author |
Radio Button values
|
PradeepPillai Pradeep
Ranch Hand
Joined: Nov 15, 2005
Posts: 183
|
|
Greetings. I have to iterate the values of radio buttons in a jsp page. But instead of the values to be printed in the jsp page, I want something else printed. For example the values could be numbers like 1, 2, 3 and what I want printed in the jsp page could be A, B, C like the following html radio button. A: <input type="radio" name="rating" value="1"> B: <input type="radio" name="rating" value="2"> C: <input type="radio" name="rating" value="3"> But I want to do this using struts. Any ideas appreciated. Thank you very much. [ June 04, 2007: Message edited by: PradeepPillai Pradeep ]
|
 |
Sanjay Virkar
Greenhorn
Joined: Apr 03, 2005
Posts: 19
|
|
You can set up a hidden paramter in your jsp. <html:hidden property="hidden_variable" /> In Submit use Javascript's onclick to assign values to the hidden parameter <html:submit onklick="document.MyForm.hidden_variable.value='1';"> </html:submit> (in above lines replace onklick's third character with 'c' I had to use misspeling so the post is accepted by server) In your form class define setter, getters for hidden parameter. public String getHidden_variable() public void setHidden_variable(String hv) Read this paramter in action class String string1 = (String)((MyForm)form).getHidden_variable(); This is not a pure struts solution but it uses javascript also [ June 04, 2007: Message edited by: Sanjay Virkar ]
|
 |
Dom Lassy
Ranch Hand
Joined: May 05, 2006
Posts: 181
|
|
If you don't need to iterate, you can use this: Or if you need to iterate: This is assuming that your form has a method called getRadioValues() that returns a list of LabelValueBeans. Also, your form should have a property called radioProp so the submittal will save the values. If you need a radio value to be selected by default, extend LabelValueBean with a selected property, and use logic:equal to determine whether or not to display "checked" in the input tag.
|
 |
Dom Lassy
Ranch Hand
Joined: May 05, 2006
Posts: 181
|
|
Found this also: http://www.ibm.com/developerworks/java/library/j-sr4.html
|
 |
Srilakshmi Vara
Ranch Hand
Joined: Jul 21, 2004
Posts: 169
|
|
with out iterating you need to map it like this 1-->A, 2-->B... Maintain two variables in you action form one holds radioNameValues(with any java structure which holds ids and values). In JSP loop through radioValues <logic:iterate id="nameval" name="formName" property="radioValues"> <bean:write name="nameval" property="label"/>: <html:radio value="<bean:write name="nameval" property="value">"/> </logic:iterate>
|
 |
M sallu
Ranch Hand
Joined: Dec 13, 2009
Posts: 42
|
|
Thanks - But that radio button is not being checked
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
M sallu please don't bump a 3 year old topic for your problem. You already have started a topic here, lets focus on your problem in that topic...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
 |
|
|
subject: Radio Button values
|
|
|