自定义spring:form以呈现不同的值和标记内容

时间:2015-07-18 18:52:28

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

我有以下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>

实际上allstatusesTerminalStatus

的枚举值集
public enum TerminalStatus {
    ACTIVE("label_1"), INACTIVE("label_2");
    String label;

    public String getLabel() {
        return label;
    }

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

    }
}

spring form允许自定义我的jsp以获得所需的结果吗?

1 个答案:

答案 0 :(得分:1)

form:options标记具有此特殊属性(itemLabel):

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