1

All my check boxes stay unchecked even though the test variable has been set to true on the server side. When i inspect the code all checkbox values=true.

   <c:if test="${not empty myObject.objectList}">
        <c:forEach items="${myObject.objectList}" varStatus="index">
            <tr class="cdata">
                <td align="center">
                    <td><form:checkbox  path="test" /> <c:out 
            value="${testName}" 
                /></td>
               </td>
            </tr>
        </c:forEach>
      </c:if>
b.d
  • 53
  • 2
  • 11

2 Answers2

0

The issue is you have not bound the checkbox to a specific item. You can bind it to a specific item in the list as below.

You must ensure consistent ordering of the list to ensure submitted values are updated correctly.

<c:if test="${not empty myObject.objectList}">
    <c:forEach var="items" items="${myObject.objectList}" varStatus="status">
        <tr class="cdata">
            <td align="center">
                <form:checkbox path="items[${status.index}].test" /> 
                ${testName}
            </td>
        </tr>
    </c:forEach>
 </c:if>
Alan Hay
  • 22,665
  • 4
  • 56
  • 110
-1

Setting values true need not necessarily reflect check boxes to be checked

Instead, you can use the checked attribute. Just write

checked ="checked"

in the checkbox and it'll reflect the change

kowsikbabu
  • 499
  • 1
  • 6
  • 23
  • Hi thanks for the input.I only want the checkboxes to be checked if the test value=true, this will set all checkboxes to checked – b.d Jun 09 '18 at 19:52
  • 1
    Then you can write a js function and set attributes to be checked if their values are true – kowsikbabu Jun 10 '18 at 04:06
  • Spring MVC will set it to checked or otherwise if it is bound correctly. – Alan Hay Jun 14 '18 at 15:10