0

In the code below testData is an HashMap. I am trying to bind checkbox with spring:bind tag. I am getting syntax errors on spring:bind. Could you tell me what is the issue in my code?

<c:forEach items="${testData}" var="test" varStatus="loopStatus"> 
     <spring:bind path="${testData[${loopStatus.index}]}.selected"> 
        <input type="hidden" name="_${status.expression}"> 
        <input type="checkbox" name="${status.expression}" value="true"> 
            <c:if test="${status.value}">checked</c:if> 
     </spring:bind> 
   </c:forEach> 

3 Answers 3

2

I'm not sure if you have another syntax error but start by changing this:

<spring:bind path="${testData[${loopStatus.index}]}.selected">

for

<spring:bind path="${testData[loopStatus.index]}.selected">
Sign up to request clarification or add additional context in comments.

Comments

0

The path in your spring:bind tag is probably wrong. I can't tell you the correct path as you haven't described the object you're binding to.

You may want to use the form:checkbox tag instead of spring bind.

1 Comment

@skaffman:testData is the object of typeHashMap here ,command name is search.
0

First, in Expression Language, ${ starts your expression and } ends it. You don't need to nest them or anything, so ${testData[${loopStatus.index}]} is your syntax error, and .selected is outside of your expression, so that should just be: ${testData[loopStatus.index].selected}.

Now, in forEach, your var attribute determines the name of the variable that holds the current item. So you rarely need to use varStatus. You can just have your test as ${test.selected}.

Finally, your checked attribute is outside of your checkbox input element!

So:

<c:forEach items="${testData}" var="test"> 
   <spring:bind path="${test.selected}"> 
      <input type="hidden" name="_${status.expression}"> 
      <input type="checkbox" name="${status.expression}" value="true" <c:if test="${status.value}">checked</c:if>>
   </spring:bind> 
</c:forEach>

(not sure you ever need the hidden field, we're not using one for any of our checkboxes).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.