【问题标题】:Iterate hashmap in struts 2 and based on its value check or uncheck a checkbox在struts 2中迭代hashmap并根据其值检查或取消选中复选框
【发布时间】: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


【解决方案1】:

代码 sn-p/它如何工作的示例

<struts:iterator value="testMap"> 
     <struts:checkbox name="abc" value="%{value}"/>   
     <struts:property value="%{value}"/>
</struts:iterator>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-20
    • 2011-08-14
    • 2020-03-13
    • 2015-12-07
    相关资源
    最近更新 更多