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>

    效果:

  • 相关阅读:
    对象引用与对象克隆
    谁被回收了
    SpringMVC 返回json
    html基础
    org.hibernate.HibernateException: No Session found for current thread
    VB6之SendMessage模拟拖放事件
    VB6之GIF分解
    VB6之反编译工具VBRezQ
    VB6之WebBrowser控件
    (转载)VB6之鼠标移出事件
  • 原文地址:https://www.cnblogs.com/qixing/p/EnumToSelect.html
Copyright © 2011-2022 走看看