Search code examples
jspmodel-view-controllerdata-bindingjsp-tagsmodelattribute

Can not bind data properly in jsp


I am trying to bind user inputs with check boxes. If the check is checked, variable should be true. Otherwise false. In my case, when user checked the check box, variable value is true(As expected) but when user not checked the check box, my variable bind with null value(Expected false). Why is it not binding with false???

I have attached the my jsp code.

JSP code

<c:forEach items="${giftDelivery.tempHistoryDto}" var="profile" varStatus="status">
     <tr class="table_rows">                            
         <td>
         <input type="checkbox" name="tempHistoryDto[${status.index}].giftStatus" <c:if test="${profile.giftStatus == true}">checked = "checked"</c:if>>
         </td>      
     </tr>                      
</c:forEach>

What am i doing wrong here.

Any help would be grateful.

Thank you very much.


Solution

  • I have found the issue. In my DTO class I have declared giftStatus as a Boolean object . I changed it to primitive type boolean.

    Thats it.. Now giftStatus variable also binding with false.

    Hope this helps..