| 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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
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
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9189
|
|
|
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?
|
 |
 |
|
|
subject: struts2 list of radio buttons
|
|
|