Recently, in my project I had to implement search functionality. I used grails createCriteria to implement it.Now I needed to apply the sorting on the result returned. My domain was something like this :
class MyEntity { OrganizationName orgName PersonName personName static constraints = { orgName('nullable', true) personName('nullable', true) } } class OrganizationName { String organizationName } class PersonName { String familyname String firstName }
The “MyEntity” could either be a person or an organization. In the view, we show just the name, and that could be either the organization-name or person-name. The list needed to be sorted by the name,irrespective of the fact, whether it is a name of a person or an organization. Grails “createCriteria” did the magic for me. I wrote something like this :
MyEntity.createCriteria ().list { orgName { order('name') } personName { order('familyName') } }
The ordering seems to ignore nulls. It sorts the MyEntity objects with orgName, groups them togethor and then sorts the MyEntity objects with personName and makes another group for them and then returns a combined, grouped sorted list of both. Hats off to grails.
Imran Mir
imran@intelligrape.com

I like this blog very much so much fantastic info.
Pingback from topsy.comTwitter Trackbacks for ASPCA Pet Insurance | In the News: The Physics Behind a Dog’s … http://www.allpet.co.uk [aspcapetinsurance.com] on Topsy.com
6364 se mcnary
An outstanding share! I’ve just forwarded this onto a coworker who has been doing a little homework on this. And he actually bought me lunch due to the fact that I discovered it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending the time to discuss this topic here on your internet site.