我想知道options tag
在Spring的表單命名空間中做了什麼。我不明白如何在docs中提到的itemValue屬性與地圖關鍵字相關。在控制器 例如說我有以下方法:Spring選項標記的用法
@ModelAttribute("rights")
public Map<ADMIN_RIGHTS, String> populateRights(){
Map<ADMIN_RIGHTS, String> rights = new LinkedHashMap<ADMIN_RIGHTS, String>();
rights.put(ADMIN_RIGHTS.ADMIN, "administrator");
rights.put(ADMIN_RIGHTS.COMP,"company");
rights.put(ADMIN_RIGHTS.EMP,"Employee");
return rights;
}
的JSP是:
<form:select path="right" >
<form:options items="${rights}"/>
</form:select>
而且屬性編輯器類:
public class RightsPropertyEditor extends PropertyEditorSupport {
@Override
public String getAsText() {
Right right = (Right) getValue();
if (right != null) {
return right.getName();
}
return super.getAsText();
}
@Override
public void setAsText(String rightStr) throws IllegalArgumentException {
if (rightStr != null && rightStr.equals("ADMIN")){
rightStr = "Adminstrator credential";
}
else if(rightStr != null && rightStr.equals("COMP")){
rightStr = "Computer credential";
}
else if(rightStr != null && rightStr.equals("EMP")){
rightStr = "Employee credential";
}
setValue(new Right(rightStr));
}
在JSP我不給itemValue和itemLabel,但仍然一切正常。那麼我在這裏錯過了什麼?