zoukankan      html  css  js  c++  java
  • 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>

    效果:

  • 相关阅读:
    iOS 倒计时及获取本时区时间
    文字上的删除线
    ios 预览文件-QLPreviewController用法
    iOS delegate、notification、KVO的区别
    mvc 详解
    app切图暂时没有iOS8的,后续继续添加
    背影图
    字体渐变
    ios for 循环 创建 九宫格
    Spherical Harmonics Lighting
  • 原文地址:https://www.cnblogs.com/qixing/p/EnumToSelect.html
Copyright © 2011-2022 走看看