Results 1 to 2 of 2
Thread: Spring binding in jsp
- 05-02-2008, 05:06 AM #1
Member
- Join Date
- May 2008
- Posts
- 1
- Rep Power
- 0
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
Class:ComponentJava Code:private List<Component> components;
exam.jspJava Code:private boolean candidateBelieving;
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.Java 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>
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
This seems very similar but is still causing problems.Java 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>
Please help
- 05-05-2008, 12:21 PM #2
For Each Radio
Your Code
Java 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>
Take this
1. u have used name="radio" , you must be having this in your dataBind. if not then have this. Better change the name to some recognizable name e.g selectedComponent
2. value="true" what does this mean. You should not use "true" here should be some value. you can use counter
3. main thing <c:if test="${status.value eq question.selectedComponent}">checked</c:if>
Hope it get clear. :)i am the future
Similar Threads
-
Dynamic Binding
By javarishi in forum New To JavaReplies: 3Last Post: 04-09-2008, 11:17 AM -
How to use Collection in Spring
By Java Tip in forum Java TipReplies: 0Last Post: 03-29-2008, 12:45 PM -
Some information about spring
By Albert in forum Web FrameworksReplies: 2Last Post: 07-02-2007, 04:08 PM -
Spring IDE for Eclipse 2.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 06-28-2007, 01:26 PM -
Spring IDE for Eclipse 2.0 RC1
By levent in forum Java SoftwareReplies: 0Last Post: 06-12-2007, 08:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks