View Single Post
  #1 (permalink)  
Old 05-02-2008, 06:06 AM
Pierre Javason Pierre Javason is offline
Member
 
Join Date: May 2008
Posts: 1
Pierre Javason is on a distinguished road
Spring binding in jsp
Hey Guys
How's things

This is my first project in the spring framework.
I've checked and read many things but still can't seem to find a solution(which i'm sure exists) to the below problem.

So i'm creating an online exam. I have a Class Question that has question Components and the jsp - exam.jsp

Class:Question with appropriate getter and setter methods
Code:
private List<Component> components;
Class:Component
Code:
private boolean candidateBelieving;
exam.jsp
Code:
<c:forEach items="${question.components}" var="component" varStatus="loopstatus"> <br> <spring:bind path="components[${loopstatus.index}].candidateBelieving"> <input type="radio" name="radio" value="true" <c:if test="${status.value == true}">checked</c:if>/> </spring:bind> <c:out value="${component}"/> </c:forEach>
My problem lies in the jsp code, in that It doesn't bind and set candidateBelieving to true but it used to and here's how.

Previously after reading http://mattfleming.com/node/134 I set name="<cut value='${status.expression}'/>" or something similar(similar because in trying to replicate it I was unable to do so.) The radiobuttons where grouped and data was binding to the command Object(Question) which was good. Until i added in <c:if test="${status.value == true}">checked</c:if> which was setup in case the user clicks the back button provided. At that point each radio button was being treated as a seperate one.

My question is how do i set the property in the spring bind tag if the radio button is ticked, have the radiobuttons as one group and have a radiobutton ticked if it was previously saved?

Is it possible to do this without the spring bind tag?

"Working with Checkboxes
Code:
<c:forEach items="${command.childArray}" var="child" varStatus="loopStatus"> <spring:bind path="command.childArray[${loopStatus.index}].selected"> <input type="hidden" name="_<c:out value="${status.expression}"/>"> <input type="checkbox" name="<c:out value="${status.expression}"/>" value="true" <c:if test="${status.value}">checked</c:if>/> </spring:bind> </c:forEach>
This seems very similar but is still causing problems.

Please help
Reply With Quote
Sponsored Links