近期使用Struts中logic标签的一些总结

1、假设存在如下类:

public class PropertyDesc
{
private int type;//确定值是以文本框显示还是列表显示
private String propertyName;
private String propertyValue;
private List<EntryDesv> propertyList;

……
}

public class EntryDesc
{
private int value;
private String UIDisplay;

……
}

2、将多个PropertyDesc对象放进HashMap中,方式如下:

Map<Integer, PropertyDesc> map = new HashMap<Integer, PropertyDesc>();

map.put(1, propertyDesc1);
map.put(2, propertyDesc2);
map.put(3, propertyDesc3);
……

request.setAttribute("map",map);


3、在页面可使用如下方式呈现:
[/code]
<logic:iterate id="attr" indexId = "index" name="map">
<logic:equal name="attr" property="value.attrType" value="6">
<select size="1" name="select">
<logic:iterate id="list" name="attr" property="value.attrList">
<option selected value="<bean:write name="list" property="value"/>">
<bean:write name="list" property="UIDisplay"/>
</option>
<option value="<bean:write name="list" property="value"/>">
<bean:write name="list" property="UIDisplay"/>
</option>
</logic:iterate>
</select>
</logic:equal>

<logic:notEqual name="attr" property="value.attrType" value="6">
<input name="txtName" type="text" value="<bean:write name="attr" property="value.attrValue"/>"/>
</logic:notEqual>
</logic:iterator>
[/code]

补充:
logic:iterator迭代HashMap

1、HashMap中存放普通的包装对象

Map<Integer, String> map=new HashMap<Integer, String>();
int index = 0;
map.put(++index, "Lily");
map.put(++index, "Lucy");

request.setAttribute("map", map);

<logic:iterate iterate id="var" name="map">
<bean:write name="var" property="key"/>
<bean:write name="var" property="value"/>
</logic:iterate>


2、HashMap中存放自定义的对象

//描述属性的对象,包含该对象的几个特征字段
AttributeDesc desc = new AttributeDesc();
Map<Integer, AttributeDesc > map=new HashMap<Integer, AttributeDesc >();
int index = 0;
map.put(++index, new String[]{"Lily", "Lucy"});

request.setAttribute("map", map);

<logic:iterate iterate id="var" name="map">
<bean:write name="var" property="key"/>
<bean:write name="var" property="value.属性名"/>
</logic:iterate>

3、HashMap中存放数组

int length = length of array;
String[] array = new String[length];

Map<Integer, String[]> map=new HashMap<Integer, String[]>();
int index = 0;
map.put(++index, new String[]{"Lily", "Lucy"});

request.setAttribute("map", map);

<logic:iterate id="var" name="map">
<bean:write name="var" property="key"/>
<logic:iterate id="str" name="var" property="value">
<bean:write name="str"/>
</logic:iterate>
</logic:iterate>

4、HashMap中存放List对象

List list = new ArrayList();

Map<Integer, List> map=new HashMap<Integer, List>();
int index = 0;
list.add("lucy");

map.put(++index, list);

request.setAttribute("map", map);

<logic:iterateid="user"name="map">
<bean:write name="user" property="key"/>
<logic:iterate name="user" property="value>
<bean:write name="value.属性名"/>
</logic:iterate>
</logic:iterate>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值