我正在尝试使用<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对象作为${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
我对此有些误解,但我不能确定是哪一个……
发布于 2012-03-29 23:24:19
您的<form:select>路径引用了名为getContent()的getter,该getter返回一个具有getter getPaperless()的对象。也许您只想在操作模型类上使用getPaperless()。
然后,要显示枚举值列表,您只需声明一个空的options标记:
<form:select path="paperless">
<form:options/>
</form:select>发布于 2016-11-18 18:19:52
您必须将枚举转换为集合,并将其放入模型中。然后在表单中使用它:像任何列表一样选择。示例代码:
在你的控制器中
model.addAttribute ("paperless", Arrays.asList(Paperless .values()));在您的jsp中
<form:select ... items="${paperless}" itemValue="name" itemLabel="description"/>发布于 2012-03-29 23:20:43
请相信,如果将Paperless.values()作为对象传递给jsp页面,然后取消对名称和描述的引用,就会得到想要的结果。
https://stackoverflow.com/questions/9927549
复制相似问题