我想知道options tag
在 Spring 的表单命名空间中做了什么。我不明白 itemValue 属性如何与文档中提到的映射键相关。比如说我在控制器中有以下方法:
@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>
而 propertyEditor 类是:
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,但仍然一切正常。那么我在这里缺少什么?