struts-layout中关于checkbox的说明

checkbox:
1.jsp的html的代码:<input type="checkbox" name="roleIds(7)"  value="7">

2.layout中collection标签
<layout:collection name="roleList" sortAction="client" styleClass="COLLECTION"
 selectName="roleIds"  selectId="oid" selectProperty="oid" selectType="checkbox" width="100%" >
 
3.对应:
input                                       collection标签
type="checkbox"-------------selectType="checkbox"
name="roleIds(7)"-中的roleIds-----selectName="roleIds"
name="roleIds(7)"-中的(7)-------selectId="oid"
value="7"---------------selectProperty="oid"

 

判断是否选中:
在该jsp页面的form bean中找出roleIds(7)的值,判断是否和value="7"相等。如果相等,就选中该checkbox
collection调用方法org.apache.commons.beanutils.PropertyUtils.getProperty(bean, property)
在该方法中,property可以有如下几种形式:
1)aaa.bbb
2)aaa(1)
3)aaa[1]
这里的参数是第2)种形式,会调用form bean 中的getRoleIds(7)方法,在该方法中,调用一个组装好的map
如果返回值不为null,就表示该条数据需要选中。

 FORM中的代码:

private Map<String, Object> mappedLocationIds = new HashMap<String, Object>();
    private Map<String, Object> mappedLocationNames = new HashMap<String, Object>();
   
 public Map getMappedLocationIds() {
  return mappedLocationIds;
 }

 public void setMappedLocationIds(Map<String, Object> mappedLocationIds) {
  this.mappedLocationIds = mappedLocationIds;
 }

 public Object getLocationIds(String key) {
  return mappedLocationIds.get(key);
 }
 
 public void setLocationIds(String key, Object value) {
  if(value != null) {
   mappedLocationIds.put(key, value.toString());
  }
 }

 public Map getMappedLocationNames() {
  return mappedLocationNames;
 }

 public void setMappedLocationNames(Map<String, Object> mappedLocationNames) {
  this.mappedLocationNames = mappedLocationNames;
 }

ACTION中的代码:

Collection locationIdColl = theForm.getMappedLocationIds().values();
   StringBuffer locationIds = new StringBuffer(512);
   for(Iterator it=locationIdColl.iterator();it.hasNext();){
    String locationId = it.next().toString();
    logger.debug("--locationId:"+locationId);
    locationIds.append(locationId).append(",");
         authList.add(auth);
   }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值