我正在尝试使用 <form:select>
在我的编辑内容 .jsp 中使用以下 ENUM标记并且找不到有关如何执行此操作的示例。
public class Content implements Serializable {
public enum Paperless {
NONE(null, ""),
EDELIVERY_RECOMMENDED("EDELIVERY_RECOMMENDED", "Recommend eDelivery"),
EDELIVERY_REQUIRED("EDELIVERY_REQUIRED", "Require eDelivery"),
EDELIVERY_REQUIRED_JUSTIFICATION("EDELIVERY_REQUIRED_JUSTIFICATION", "Require eDelivery w/out justification");
private String name;
private String description;
Paperless(String name, String description) {
this.name = name;
this.description = description;
}
public String getName() {
return this.name;
}
public String getDescription() {
return this.description;
}
}
....
上面的内容对象作为 ${content}
传递到我的 .jsp 文件.
我正在努力
<form:select path="content.Paperless">
<form:options items="${content.Paperless}" itemLabel="name"/>
</form:select>
它抛出一个异常......
org.springframework.beans.NotReadablePropertyException: Invalid property 'content' of bean class [com.fettergroup.cmt.model.Content]: Bean property 'content' is not readable or has an invalid getter method: Does the return type of the getter match the parameter
我对此有些误解,但我无法确定是哪一个...
最佳答案
你的 <form:select>
path 指的是一个名为 getContent() 的 getter,它返回一个具有 getPaperless() getPaperless() 的对象。也许您想在 Action 模型类上只使用 getPaperless()。
然后要显示枚举值列表,您只需要声明一个空的选项标签:
<form:select path="paperless">
<form:options/>
</form:select>
关于java - 如何在 <form :select> 中使用 Java ENUM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9927549/