Do रूप
public enum TestType {
MAN("Man"),
FEMALE("Female");
private String description;
private TestType(String description) {
this.description = description;
}
public String getValue() {
return name();
}
public void setValue(String value) {}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
इस प्रकार है और एक कस्टम बांधने की मशीन के रूप में रजिस्टर
dataBinder.registerCustomEditor(TestType.class, new PropertyEditorSupport() {
@Override
public void setAsText(String value) throws IllegalArgumentException {
if(StringUtils.isBlank(value))
return;
setValue(TestType.valueOf(value));
}
@Override
public String getAsText() {
if(getValue() == null)
return "";
return ((TestType) getValue()).name();
}
});
फिर
<form:radiobuttons path="type" items="${testTypeList}" itemLabel="description"/>
रूप
model.addAttribute(TestType.values());
इस प्रकार आप अपने TestType की स्थापना इस प्रकार है
स्रोत
2010-08-13 15:25:34
मेरी गलती। प्रकार _Enum टाइप_ मैं _TestType टाइप_ में बदल गया और यह ठीक है! –
Alexander