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);
}