jsp file
<s:iterator value="questions" status="status">
<table border="3px" bgcolor="yellow">
<tr bgcolor="white" >
<td nowrap><s:property value="QuestionNumber"/></td>
<td nowrap><s:property value="Question"/></td>
</tr>
<tr>
<td nowrap><input type="radio" name="<s:property value="QuestionNumber"/>" value="1"/><s:property value="Option1"/></td>
<td nowrap><input type="radio" name="<s:property value="QuestionNumber"/>" value="2"/><s:property value="Option2"/></td>
</tr>
<tr>
<td nowrap><input type="radio" name="<s:property value="QuestionNumber"/>" value="3"/><s:property value="Option3"/></td>
<td nowrap><input type="radio" name="<s:property value="QuestionNumber"/>" value="4"/><s:property value="Option4"/></td>
</tr>
</table>
<s:hidden> </s:hidden>
</s:iterator>
<s:hidden id="answers" value="answers"/>
<s:submit name="submit" onclick="submitform()"/>
</s:form>
property values are being populated from DB using the Action class.
My problem is that i want to collect the list answers for a quiz and get it to the java classes for evaluation of score. Im not able to get any idea as how to do it
My DB has Questions table with the list of questions with options and correct answer.
I have a Question Bean Object.
You have an Action with a
private List<Question> questions;, with Getter and Setter.You populate your JSP reading the list from the Getter.
You can post that list back from the JSP to the Action’s Setter by using OGNL for keeping informations on lines detail.
To do this, use Struts tags (
<s:radioinstead of<radio) and set a name including the index of the line.For example, with a textfield, instead of
use something like (untested, maybe some adjustments needed)
Just adapt this for your radio case,
and in the Action you will receive your List fully populated.
(You can even validate a list posted like this usign Visitor validator: not your case, but it’s worth knowing).