Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Posts
    1
    Rep Power
    0

    Default 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
    Java Code:
    private List<Component> components;
    Class:Component
    Java Code:
    private boolean candidateBelieving;
    exam.jsp
    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>
    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
    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>
    This seems very similar but is still causing problems.

    Please help

  2. #2
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default 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

  1. Dynamic Binding
    By javarishi in forum New To Java
    Replies: 3
    Last Post: 04-09-2008, 12:17 PM
  2. How to use Collection in Spring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-29-2008, 01:45 PM
  3. Some information about spring
    By Albert in forum Web Frameworks
    Replies: 2
    Last Post: 07-02-2007, 05:08 PM
  4. Spring IDE for Eclipse 2.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 06-28-2007, 02:26 PM
  5. Spring IDE for Eclipse 2.0 RC1
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-12-2007, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •