关于Jsp页面的jstl标签的级联属性的异常。
Posted 渔翁
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于Jsp页面的jstl标签的级联属性的异常。相关的知识,希望对你有一定的参考价值。
使用SpringMVC框架时,当我做表单回显时。
情景描述。Employee 类有一个Department类的属性。这两各类存在多对一关联关系。
下面是Employee类的属性的定义。
public class Employee { private Integer id; private String name; private String email; private int gender; private Department department; }
下面是Employee类的属性的定义。
public class Department { private Integer id; private String departmentName; }
当我在添加Employee 对象的页面做部门信息的表单回显时。相关的jsp页面如下。
<form:form action="input" method="POST" modelAttribute="employee"> Name: <form:input path="name"/> <br> Email: <form:input path="email"/> <br> <% Map<Integer, String> genders = new HashMap(); genders.put(0, "Female"); genders.put(1, "Male"); request.setAttribute("genders", genders); %> Gender: <form:radiobuttons path="gender" items="${genders}"/> <br> <%-- jstl是支持级联属性的,在这里我想选择的部门id,则直接写Employee类中的department属性再".id"就可以了。 而后面的itemLabel 属性和 itemValue 属性。就不用再加department这个前缀了。直接写Department类的属性名称即可。 Department: <form:select path="department.id" items="${departments}" itemLabel="department.departmentName" itemValue="department.id"></form:select> --%> Department: <form:select path="department.id" items="${departments}" itemLabel="departmentName" itemValue="id"></form:select> <br> <input type="submit" name="Submit"> <br> </form:form>
在上述jsp页面的代码中,如果把注释里的代码跟注释外面的代码换一下就会出现异常。NotReadablePropertyException
异常如下:
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/views/input.jsp at line 39 36: Department: <form:select path="department.id" items="${departments}" 37: itemLabel="department.departmentName" itemValue="department.id"></form:select> 38: --%> 39: Department: <form:select path="department.id" items="${departments}" 40: itemLabel="department.departmentName" itemValue="department.id"></form:select> 41: <br> 42: <input type="submit" name="Submit">
org.springframework.beans.NotReadablePropertyException: Invalid property ‘department‘ of bean class [com.zcd.ssh.beans.Department]: Bean property ‘department‘ is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:633)
org.springframework.beans.AbstractNestablePropertyAccessor.getNestedPropertyAccessor(AbstractNestablePropertyAccessor.java:850)
org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyAccessorForPropertyPath(AbstractNestablePropertyAccessor.java:827)
org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:622)
org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:202)
org.springframework.web.servlet.tags.form.OptionWriter.renderFromCollection(OptionWriter.java:180)
org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:133)
以上是关于关于Jsp页面的jstl标签的级联属性的异常。的主要内容,如果未能解决你的问题,请参考以下文章