我在尝试提交html选项选择表时遇到以下错误,所选的选项值未转换为受尊重的枚举类型。
无法将类型'java.lang.String'的属性值转换为属性'portalLayoutLocation'的必需类型'net.mis.lookup.model.PortalLayoutLocation';嵌套异常是java.lang.IllegalStateException:无法将类型[java.lang.String]的值转换为属性“portalLayoutLocation”的必需类型[net.mis.lookup.model.PortalLayoutLocation]:找不到匹配的编辑器或转换策略
<select name="portalLayoutLocation" id="portalLayoutLocation">
<option value="">Choose a PortalLayoutLocation</option>
<option value="1">PortalLayoutLocation.HEADER_MAIN_LOGO</option>
<option value="2">PortalLayoutLocation.HOMEPAGE_TECHNICAL_TIP_OF_THE_DAY</option
<option value="3">PortalLayoutLocation.HOMEPAGE_CARTOON_OF_THE_DAY</option>
<option value="4">PortalLayoutLocation.FOOTER_LOGO</option>
<option value="5">PortalLayoutLocation.PORTAL_HEADER_MAIN_ADVERTISEMENT</option>
<option value="6">PortalLayoutLocation.PORTALHOMELAYOUT_HOMECONTENT_ADVERTISEMENT</option>
<option value="7">PortalLayoutLocation.PORTALHOMELAYOUT_WIDESIDEBAR_ADVERTISEMENT</option>
<option value="8">PortalLayoutLocation.PORTALLAYOUT_NARROWSIDEBAR_ADVERTISEMENT</option>
</select>
public enum PortalLayoutLocation {
HEADER_MAIN_LOGO(1, "PortalLayoutLocation.HEADER_MAIN_LOGO"),
HOMEPAGE_TECHNICAL_TIP_OF_THE_DAY(2, "PortalLayoutLocation.HOMEPAGE_TECHNICAL_TIP_OF_THE_DAY"),
HOMEPAGE_CARTOON_OF_THE_DAY(3, "PortalLayoutLocation.HOMEPAGE_CARTOON_OF_THE_DAY"),
FOOTER_LOGO(4, "PortalLayoutLocation.FOOTER_LOGO"),
PORTAL_HEADER_MAIN_ADVERTISEMENT(5, "PortalLayoutLocation.PORTAL_HEADER_MAIN_ADVERTISEMENT"),
PORTALHOMELAYOUT_HOMECONTENT_ADVERTISEMENT(6, "PortalLayoutLocation.PORTALHOMELAYOUT_HOMECONTENT_ADVERTISEMENT"),
PORTALHOMELAYOUT_WIDESIDEBAR_ADVERTISEMENT(7, "PortalLayoutLocation.PORTALHOMELAYOUT_WIDESIDEBAR_ADVERTISEMENT"),
PORTALLAYOUT_NARROWSIDEBAR_ADVERTISEMENT(8, "PortalLayoutLocation.PORTALLAYOUT_NARROWSIDEBAR_ADVERTISEMENT");
private int typeCode;
private String messageKey;
private PortalLayoutLocation(int typeCode, String messageKey) {
this.typeCode = typeCode;
this.messageKey = messageKey;
}
public int toInt() {
return typeCode;
}
public static PortalLayoutLocation fromInt(int value) {
switch (value) {
case 0:
return null;
case 1:
return HEADER_MAIN_LOGO;
case 2:
return HOMEPAGE_TECHNICAL_TIP_OF_THE_DAY;
case 3:
return HOMEPAGE_CARTOON_OF_THE_DAY;
case 4:
return FOOTER_LOGO;
case 5:
return PORTAL_HEADER_MAIN_ADVERTISEMENT;
case 6:
return PORTALHOMELAYOUT_HOMECONTENT_ADVERTISEMENT;
case 7:
return PORTALHOMELAYOUT_WIDESIDEBAR_ADVERTISEMENT;
case 8:
return PORTALLAYOUT_NARROWSIDEBAR_ADVERTISEMENT;
default:
throw new UnsupportedOperationException("Unexpected enum value : " + value);
}
}
public int getTypeCode() {
return typeCode;
}
public String getMessageKey() {
return messageKey;
}
public String getLocalozedMessage() {
return StaticMessageSource.getMessage(messageKey);
}
@Override
public String toString() {
return getLocalozedMessage();
}
}
答案 0 :(得分:0)
使用HEADER_MAIN_LOGO
,HOMEPAGE_TECHNICAL_TIP_OF_THE_DAY
,...代替值,而不是1,2,......