PDA

View Full Version : How to sort a column with an IdentityValueProvider<T>?



icfantv
24 Feb 2012, 2:33 PM
I was told that if I needed to render a column using more than one property on a bean to do the following:


ColumnConfig<Foo, Foo> cc = new ColumnConfig(new IdentityValueProvider<Foo>(), ...);

The problem I'm seeing is that when I got to sort this column, no sort info gets sent to the server so the server doesn't know what column to sort by. With a PropertyAccess<T> implementation, it uses the interface method name as the column name to sort by and this is what's sent to the server.

What can I do to have something sent to the server to indicate this column?

margozzi
26 Sep 2013, 10:10 AM
Did you ever solve this problem? I am facing the exact same issue.

icfantv
26 Sep 2013, 12:03 PM
Yes. It's the value returned by IdentityValueProvider.getPath(). I hadn't realized I never posted a solution. Sorry about that. It's been a while.

margozzi
26 Sep 2013, 3:11 PM
Thank you for the prompt reply. This is what I ended up doing with success:



ColumnConfig<Job, Job> stateColumn = new ColumnConfig<Job, Job>(new IdentityValueProvider<Job>("state"), 100, _jobConstants.state());

icfantv
26 Sep 2013, 6:27 PM
The one downside with that what you have currently is that the cell renderer will, by default, just call Job.toString() for the contents of the cell. This is most likely not what you want.

If Job.toString() does return what you want I might question your usage of the method as it is typically used for debugging and logging. Sure, you can make it do whatever you want, but I tend to really dislike APIs that rely on toString() for anything that is remotely related to business-logic.

You will need a custom cell renderer, probably one that extends AbstractCell<Job> to define exactly what you want to display. If you go this route, GWT recommends you check for a null object when you implement the render(...) method.

Please let us know if you need additional help.

margozzi
26 Sep 2013, 8:22 PM
Yes, Sorry, I did not include the code that implemented the AbstractCell<Job> in the above snippet.
I was unable to figure out where the getPath() was supposed to go. I eventually discovered I could pass it in the constructor. I wanted to post that in case other came after me looking for the solution.