开发者

<table:column> Roo-tag for property of referenced entity

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}" duplica开发者_如何学Pythonte="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>


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜