【问题标题】:Customize spring:form to render different value and tag content自定义 spring:form 以呈现不同的 value 和 tag 内容
【发布时间】:2015-07-18 18:52:27
【问题描述】:

我有以下jsp:

<form:select path="terminalStatus">
     <form:options items="${allStatuses}"/>
</form:select>

呈现如下:

<select id="terminalStatus" name="terminalStatus">
     <option value="ACTIVE" selected="selected">ACTIVE</option>
     <option value="INACTIVE">INACTIVE</option>
</select>

我希望它呈现出一点不同。像这样:

<select id="terminalStatus" name="terminalStatus">
     <option value="ACTIVE" selected="selected">label_1</option>
     <option value="INACTIVE">label_2</option>
</select>

其实allstatuses就是TerminalStatus的枚举值集合:

public enum TerminalStatus {
    ACTIVE("label_1"), INACTIVE("label_2");
    String label;

    public String getLabel() {
        return label;
    }

    private TerminalStatus(String label) {
        this.label = label;

    }
}

spring 表单是否允许自定义我的 jsp 以获得所需的结果?

【问题讨论】:

    标签: java jsp spring-mvc taglib spring-form


    【解决方案1】:

    form:options 标签对此有特殊属性(itemLabel):

    <form:select path="terminalStatus">
        <form:options items="${allStatuses}" itemLabel="label"/>
    </form:select>
    

    【讨论】:

      猜你喜欢
      • 2020-05-22
      • 2012-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-27
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多