【发布时间】:2014-02-24 07:07:50
【问题描述】:
我需要使用 struts 2 迭代一个 hashmap,如果 hashmap 的值为 true,我需要选中复选框,否则不要选中它。
我已经能够遍历地图,但我无法在其中进行条件检查。如果 hashmap 的值为 true,我需要选中复选框,如果为 false,我需要保持未选中状态。如何在迭代器中使用 if 子句来检查 hashmap 的值。
下面是我正在使用的代码sn-p
testMap=new HashMap<String, String>();
testMap.put("1","true");
testMap.put("2","false");
================================================ ====================================
<struts:iterator value="testMap.entrySet()">
<input type="checkbox" name="abc" value='<struts:property value="%{value}"/>'>
<struts:property value="%{value}"/>
【问题讨论】:
-
为什么不使用
struts:checkbox? -
复选框没问题,但问题是当 hashmap 的值为 true 时,如何有条件地将 check="checked" 子句放在复选框中
-
Struts 会根据 value 属性放置它。
-
您能否提供代码 sn-p/示例说明它的工作原理?
标签: jsp checkbox struts2 hashmap