【发布时间】:2013-06-19 18:45:55
【问题描述】:
这是来自我的控制器的相关代码:
@ModelAttribute("store_location_types")
public StoreLocationType[] getStoreLocationTypes() {
return StoreLocationType.values();
}
这里是 StoreLocationType 的定义,定义在同一个控制器中:
private enum StoreLocationType {
PHYSICAL("Physical"),
ONLINE("Online");
private String displayName;
private String value;
private StoreLocationType(String displayName) {
this.displayName = displayName;
this.value = this.name();
}
public String getDisplayName() {
return this.displayName;
}
public String getValue() {
return this.value;
}
}
这里是相关的JSP代码:
<li>
<label>Location Type:</label>
<form:radiobuttons path="StoreLocationType" items="${store_location_types}" itemLabel="displayName" itemValue="value"/>
</li>
这是页面渲染时生成的内容:
<li>
<label>Location Type:</label>
<span>
<input id="StoreLocationType1" name="StoreLocationType" type="radio" value="">
<label for="StoreLocationType1">Physical</label>
</span>
<span>
<input id="StoreLocationType2" name="StoreLocationType" type="radio" value="">
<label for="StoreLocationType2">Online</label>
</span>
</li>
值属性没有被我的枚举的“值”字段填充。我在这里做错了什么?我希望看到的是:
<span>
<input id="StoreLocationType1" name="StoreLocationType" type="radio" value="PHYSICAL">
<label for="StoreLocationType1">Physical</label>
</span>
<span>
<input id="StoreLocationType2" name="StoreLocationType" type="radio" value="ONLINE">
<label for="StoreLocationType2">Online</label>
</span>
输入标签的value属性应该是StorLocationType.ONLINE.getValue()的值
【问题讨论】:
标签: java jsp spring-mvc enums radio-button