java枚举类型转换为Struts2的select的数据

枚举类:AppSortEnum.java

public enum AppSortEnum {
CORE(0, "核心应用"),
ENJOYMENT(1, "娱乐应用"),
MESSAGE(2, "消息提醒");

private int index;
private String name;
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

private AppSortEnum(int index, String name) {
this.index = index;
this.name = name;
}
}

 

在Action中使用:

public String presentUI(){

ActionContext.getContext().put("appSort", AppSortEnum.values());
ActionContext.getContext().put("appType", AppTypeEnum.values());
ActionContext.getContext().put("range", areaService.queryAll());
return "presentUI";
}

在jsp中使用appSort和appType:

<tr>
<td class="rightAlign"><label>类型:</label></td>
<td>
<s:iterator value="#appType" status="type">
<input type="radio" id="type" name="appInfo.type" value="<s:property value='index'/>" checked><s:property value="name"/>
</s:iterator>
<label id='requiredLabel'></label>
</td>
</tr>
<tr>
<td class="rightAlign"><label>分类:</label></td>
<td>
<s:select list="#appSort" listKey="index" id="sort" name="appInfo.sort" listValue="name"></s:select>
<label id='requiredLabel'>*</label>
</td>
</tr>

效果:

posted @ 2013-06-25 16:44  七星6609  阅读(2529)  评论(0编辑  收藏  举报