Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc org.springframework.expression.spel.SpelEvaluationException:EL1027E:(位置4):索引到类型';com.test.domain.Employee';不支持_Spring Mvc_Jsp Tags_Spring Roo_Jspx_Spelevaluationexception - Fatal编程技术网

Spring mvc org.springframework.expression.spel.SpelEvaluationException:EL1027E:(位置4):索引到类型';com.test.domain.Employee';不支持

Spring mvc org.springframework.expression.spel.SpelEvaluationException:EL1027E:(位置4):索引到类型';com.test.domain.Employee';不支持,spring-mvc,jsp-tags,spring-roo,jspx,spelevaluationexception,Spring Mvc,Jsp Tags,Spring Roo,Jspx,Spelevaluationexception,我正在开发一个SpringRoo应用程序,在list(在list.jspx中)中显示对象时,我将获得引用对象的所有属性。例如: @RooJavaBean @RooToString @RooJpaActiveRecord public class Employee { @NotNull private String empName; @ManyToOne private Department department; } <table

我正在开发一个SpringRoo应用程序,在list(在list.jspx中)中显示对象时,我将获得引用对象的所有属性。例如:

@RooJavaBean
@RooToString    
@RooJpaActiveRecord

public class Employee {    
    @NotNull
    private String empName;    
    @ManyToOne
    private Department department;
}
<table:table data="${exampleusers}" typeIdFieldName="userId" id="l_com_project_Example_ExampleUser" path="/exampleUserList">
部门呢

@RooJavaBean    
@RooToString    
@RooJpaActiveRecord    
public class Department {    
    @NotNull
    private String deptName;

   @NotNull
   private String deptLocation;
}
现在,在roo中构建了一个web项目,并添加了部门条目和员工条目之后,我在员工列表中得到了一个难看的表。将显示Department实体中的所有属性,我的意图是显示Department名称(deptName)

尝试在list.jspx中进行如下更改:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <page:list id="pl_com_test_domain_Employee" items="${employees}" z="user-managed">
        <table:table data="${employees}" id="l_com_test_domain_Employee" path="/employees" z="user-managed">
            <table:column id="c_com_test_domain_Employee_Department" property="department.deptName" z="user-managed"/>
            <table:column id="c_com_test_domain_Employee__DeptLocation" property="deptLocation" z="user-managed"/>
        </table:table>
    </page:list>

我该怎么办?

我得到了答案,我在这里分享它:

为了避免上述错误,我将table.tagx更改如下:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0">
    <jsp:directive.page contentType="text/html;charset=UTF-8"/>
    <jsp:output omit-xml-declaration="yes"/>
    <page:list id="pl_com_test_domain_Employee" items="${employees}" z="user-managed">
        <table:table data="${employees}" id="l_com_test_domain_Employee" path="/employees" z="user-managed">
            <table:column id="c_com_test_domain_Employee_Department" property="department.deptName" z="user-managed"/>
            <table:column id="c_com_test_domain_Employee__DeptLocation" property="deptLocation" z="user-managed"/>
        </table:table>
    </page:list>
表4.tagx:line-84:

替换此项:

<spring:eval expression="item[column]" htmlEscape="false" />
<spring:eval expression="item[typeIdFieldName]"/>

为此:

<spring:eval expression="item.${column}"  htmlEscape="false" />
<c:set var="itemId"><spring:eval expression="item.${typeIdFieldName}"/></c:set>

表4.tagx:line-95:

替换此项:

<spring:eval expression="item[column]" htmlEscape="false" />
<spring:eval expression="item[typeIdFieldName]"/>

为此:

<spring:eval expression="item.${column}"  htmlEscape="false" />
<c:set var="itemId"><spring:eval expression="item.${typeIdFieldName}"/></c:set>

现在,您可以从如下对象访问属性:

 <page:list id="pl_com_test_domain_Employee" items="${employees}" z="user-managed">
    <table:table data="${employees}" id="l_com_test_domain_Employee" path="/employees" z="user-managed">
        <table:column id="c_com_test_domain_Employee_Department"  property="department.deptName" z="user-managed"/>
        <table:column id="c_com_test_domain_Employee_DeptLocation" property="deptLocation" z="user-managed"/>
    </table:table>
</page:list>

谢谢你


钱丹

只为未来的谷歌人准备:

SpringRoo有自己的
taglib,它需要
typeIdFieldName
属性!如果您没有指定,则此
typeIdFieldName
默认为
id

关于域模型中的注释,它什么都不知道

因此,如果所列实体的标识符属性不是
id
,则需要手动使用此
typeIdFieldName
字段为其指定。例如:

@RooJavaBean
@RooToString    
@RooJpaActiveRecord

public class Employee {    
    @NotNull
    private String empName;    
    @ManyToOne
    private Department department;
}
<table:table data="${exampleusers}" typeIdFieldName="userId" id="l_com_project_Example_ExampleUser" path="/exampleUserList">

在我的例子中,
exampleUser
实体的标识符是
userId
,而不是公共的
id
。我花了大约2个小时的调试时间。。。祝你好运