Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Radio Button values

 
Ranch Hand
Posts: 190
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Found this also:
http://www.ibm.com/developerworks/java/library/j-sr4.html
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks - But that radio button is not being checked

 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic