• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

struts2 list of radio buttons

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
i have a list of questions. each question object is declared like this:


each Answer is declared like this:

i want to iterate of the questions and display them like this:
1. How was your day?
<input type="radio" name="group1" value="1">Very good
<input type="radio" name="group1" value="2">Moderate
<input type="radio" name="group1" value="3">Horrible
2. Who is could be your best friend?
<input type="radio" name="group1" value="1">Mother
<input type="radio" name="group1" value="2">Father
<input type="radio" name="group1" value="3">Sister
<input type="radio" name="group1" value="3">Brother

I would like it to save for each question what answer was chosen.

How can I do it please?
 
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't specify how is the question declared in your action, I suppose there is a list of Questions in your action class. So you need to iterate over the questions, print the question one by one along with the options using the radio tag like this



I think that should work, I didn't test it. When you submit the form back, you need to catch the radio button values into a List or array. See the struts 2 tag reference for more info on the tags...
 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
How can I catch the radio button values into a List or array?
thanks
 
Ankit Garg
Sheriff
Posts: 9709
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just declare a list or array of name answer in the target action...
 
Jordan Smith
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi!
I was trying your solution
but i get the following error:

Error on line 25, column 9 in template/simple/radiomap.ftl
stack.findValue(parameters.listKey) is undefined.
It cannot be assigned to itemKey
The problematic instruction:
----------
==> assignment: itemKey=stack.findValue(parameters.listKey) [on line 25, column 9 in template/simple/radiomap.ftl]
in user-directive s.iterator [on line 23, column 1 in template/simple/radiomap.ftl]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Error on line 25, column 9 in template/simple/radiomap.ftl
stack.findValue(parameters.listKey) is undefined.
It cannot be assigned to itemKey
at freemarker.core.Assignment.accept(Assignment.java:111)
at freemarker.core.Environment.visit(Environment.java:209)
at freemarker.core.IfBlock.accept(IfBlock.java:82)


why is it?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic