关于Jsp页面的jstl标签的级联属性的异常。

2021-06-29 12:03

阅读:455

标签:ons   asp   map   异常   proc   post   java   setattr   invalid   

使用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> 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: 

在上述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标签的级联属性的异常。

标签:ons   asp   map   异常   proc   post   java   setattr   invalid   

原文地址:http://www.cnblogs.com/GooPolaris/p/7141355.html


评论


亲,登录后才可以留言!