<表:列>引用实体属性的 Roo 标签

发布于 2024-12-09 18:42:13 字数 701 浏览 2 评论 0原文

我在 Roo 项目中有两个班级(学生、班级)及其脚手架视图。

学生和班级有 1:1 的关系

在学生的 list.jspx 中,我想显示班级属性的列。

我不知道赋予 table:column-tag 的正确属性。 下面的示例给出了错误:

SpelEvaluationException:EL1027Epos 4):不支持对“com.pupil”类型进行索引

<table:table data="${pupil}" duplicate="true" id="l_com_pupil" path="/admin/pupil" z="user-managed">
   <table:column id="c_com_pupil_pupilName" property="pupilName" z="user-managed"/>
   <!-- I'd like to display the attribute teacher_name of the class 'class' here but it doesn't work -->
   <table:column id="c_com_pupil_class_teacherName" property="teacherName"  z="user-managed"/>
</table:table>

I've got a two classes (pupil, class) in a Roo-project and their scaffolded views.

pupil and class have a 1:1 relationship

In the list.jspx of pupil I'd like to display a column for a property of class.

I don't know the correct attributes to give to the table:column-tag.
This following example gives the error:

SpelEvaluationException: EL1027Epos 4): Indexing into type 'com.pupil' is not supported

<table:table data="${pupil}" duplicate="true" id="l_com_pupil" path="/admin/pupil" z="user-managed">
   <table:column id="c_com_pupil_pupilName" property="pupilName" z="user-managed"/>
   <!-- I'd like to display the attribute teacher_name of the class 'class' here but it doesn't work -->
   <table:column id="c_com_pupil_class_teacherName" property="teacherName"  z="user-managed"/>
</table:table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青衫负雪 2024-12-16 18:42:13

您可以简单地通过在 ApplicationServiceFactoryBean.java 中实现 Teacher 实体的转换器来实现此目的,而不用搞乱 jspx 文件。

请参阅下面的转换方法示例。

static class com.mycompany.test.controllers.ApplicationConversionServiceFactoryBean.TeacherConverter implements org.springframework.core.convert.converter.Converter<com.mycompany.test.domain.master.Teacher, java.lang.String>  {
        public String convert(Teacher teacher) {
            return new StringBuilder().append(teacher.getName()).toString();
        }
}

默认情况下,Roo 生成这些转换器,并将它们存储在 ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj 文件中。

您可以将这个aspectJ文件中Teacher实体的相关方法推入重构
ApplicationServiceFactoryBean.java 文件,然后实现您自己的转换,该转换将用于在应用程序中显示 Teacher 名称,如上例所示。

干杯,祝 Roo 一切顺利!

Instead of messing around with the jspx files, you can simply do this by implementing a converter for the Teacher entity within the ApplicationServiceFactoryBean.java.

See the below conversion method for an example.

static class com.mycompany.test.controllers.ApplicationConversionServiceFactoryBean.TeacherConverter implements org.springframework.core.convert.converter.Converter<com.mycompany.test.domain.master.Teacher, java.lang.String>  {
        public String convert(Teacher teacher) {
            return new StringBuilder().append(teacher.getName()).toString();
        }
}

By default, Roo generates these converters and they are stored within the ApplicationConversionServiceFactoryBean_Roo_ConversionService.aj file.

You can push in refactor the related method for the Teacher entity from this aspectJ file into the
ApplicationServiceFactoryBean.java file and then implement your own conversion which will be used to show the Teacher name across the application as in the above example.

Cheers and all the best with Roo!

世界如花海般美丽 2024-12-16 18:42:13

我就是这样做的,不是为了列出,而是为了在查看学生实体时显示老师的姓名:

  • 编辑控制器,特别是方法 show (当然,在 java 文件中,而不是在 aj 文件中) 。
  • 向您的 UI 模型添加一个属性,例如“teacherName”(使用 Model.addAttribute),您可以在其中使用所需的名称填充teacherName。
  • 在 show.jspx 文件中添加如下内容:

    ${teacherName}


    >

(或者,您可以使用自己的参数创建一个新的 tagx 文件)

希望它有所帮助。

拉杜

This is how I did it, not for listing, but rather for showing the name of the teacher when you view the pupil entity:

  • Edit the controller and specifically the method show (in the java file, not in the aj file, of course).
  • Add an attribute to your UI Model, for instance "teacherName" (use Model.addAttribute), where you populate the teacherName with the desired name.
  • Add in the show.jspx file something like:

    <div><label for="_pupilTeacher">Teacher Name:</label><div class="box">${teacherName}</div></div><br/>

(alternatively, you could create a new tagx file with your own parameters)

Hope it helped.

Radu

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文