wood burning stoves*
The moose likes Struts and the fly likes struts2 list of radio buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 list of radio buttons " Watch "struts2 list of radio buttons " New topic
Author

struts2 list of radio buttons

Jordan Smith
Ranch Hand

Joined: Apr 06, 2008
Posts: 89
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?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jordan Smith
Ranch Hand

Joined: Apr 06, 2008
Posts: 89
Hi
How can I catch the radio button values into a List or array?
thanks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9307
    
  17

Just declare a list or array of name answer in the target action...
Jordan Smith
Ranch Hand

Joined: Apr 06, 2008
Posts: 89
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 list of radio buttons