【问题标题】:Can not bind data properly in jspjsp中无法正确绑定数据
【发布时间】:2019-05-24 17:36:58
【问题描述】:

我正在尝试将用户输入与复选框绑定。如果选中检查,变量应该为真。否则为假。在我的情况下,当用户选中复选框时,变量值为 true(如预期)但当用户未选中复选框时,我的变量绑定空值(预期为 false)。为什么不绑定false???

我已经附上了我的jsp代码。

JSP 代码

<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>

我在这里做错了什么。

任何帮助将不胜感激。

非常感谢。

【问题讨论】:

  • 你为什么这样做name="tempHistoryDto[${status.index}].giftStatus"而不是name="${profile.giftStatus)"

标签: jsp model-view-controller data-binding jsp-tags modelattribute


【解决方案1】:

我找到了问题。 在我的 DTO 类中,我已将 giftStatus 声明为 Boolean 对象。我把它改成了原始类型boolean

就是这样。现在giftStatus 变量也与false 绑定。

希望这会有所帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-10
    相关资源
    最近更新 更多