On 26.01.2010 20:00, Michael Prescott wrote:
> How do you go about making a computed column in a Grid sortable?  The docs
> on Grid are great, but in the example the computed column is non-sortable.
> Can I do it by providing a PropertyConduit through the grid's BeanModel
> model?
>
> Michael
>
>   
I have quite a bit of trouble with this. On almost every page we have a
grid which has at least half of the columns computed or with cell values
lazy loaded via foreign keys.

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}

The backing database model:    Employee (n) : (1) Person

Of course I have to sort based on firstName value, and not based on the
foreign key id value in the main entity.

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.

The grid component only references the "model" model.

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.
- 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.

On the other hand I am encouraged that even some point-and-click
non-programmer-friendly web frameworks like Oracle Application Express
do not have an obvious solution for such ordinary everyday use-cases.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to