On Thu, 04 Feb 2010 16:06:08 -0200, Vangel V. Ajanovski <a...@ii.edu.mk> wrote:

For example in 100% of cases we have source of the grid as
List<Employee>, where Employee is an Entity (via Hibernate).
And in 90% the cells we have something like this
${employee.person.firstName}
${employee.person.lastName}

You could, for example, add a @Transient String getFirstName() { return getPerson.getFirstName(); } method. Grid and DisplayModel would recognize it automatically. Even in non-Tapestry contexts, this can be very handy.

So, this approach worked for me, but I am not sure that it's the right
way, or that it's a proper way.

    @Inject
    private PropertyConduitSource pcSource;
    @Inject
    private BeanModelSource beanModelSource;
    @Inject
    private Messages messages;
    @Property
    private BeanModel<CourseEnrollment> model;

    void pageLoaded() {
        this.model = beanModelSource.createDisplayModel(Employee.class,
messages);
        this.model.add("firstName",
pcSource.create(Employee.class,"person.firstName")).sortable(true);
        this.model.add("lastName",
pcSource.create(Employee.class,"person.lastName")).sortable(true);
        this.model.add("staffType", null).sortable(false);
        this.model.reorder("firstName, lastName, staffType");
    }

I don't even know that this code is OK, but it worked.

IMHO, it's absolutely correct. A textbook example, even. :)

I am bothered with this solution becase:
- This is too much code for something that should be much simpler, and I
am thinking about making a generic version, but I guess I still haven't
learned enough of Tapestry to succeed in that.

To do what you want, BeanModelSource would need to look for properties recursively, and I don't think it would be a good idea. A potentially large number of properties would be found, most of then useless.

- I have code duplication. The names of the properties that should be
displayed and sorted are written twice, once when creating the
PropertyConduit and the other time is in the template.

Why again in the template?

--
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer, and instructor Owner, software architect and developer, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to