google app engine - Grails constraints GORM-JPA always sorting alphabeticaly -


in grails app, in use gorm-jpa, cannot define order of elements of class using constraints. if autogenerate views, sorted alphabetically, instead of defined order. here's source class:

package kbdw    import javax.persistence.*; // import com.google.appengine.api.datastore.key;  @entity class organisatie implements serializable {      @id     @generatedvalue(strategy = generationtype.identity)     long id      @basic     string naam      @basic     string telefoonnummer      @basic     string email      @basic     organisatietype type      @basic     string adreslijneen      @basic     string adreslijntwee      @basic     string gemeente      @basic     string postcode      @basic     string faxnummer        static constraints = {         id visible:false         naam size: 3..75         telefoonnummer size: 4..18         email email:true         type blank:false         adreslijneen size:5..250         adreslijntwee blank:true         gemeente size: 2..100         postcode size: 4..10         faxnummer size: 4..18     } }  enum organisatietype {     school,     nonprofit,     bedrijf } 

the variable names in dutch, should clear (organisatie = organisation, naam = name, adres = address, ...).

how force app use order of properties? need use @ annotations?

thank you!

yvan (ps: it's deploying on google app engine ;-) )

try installing , hacking scaffolding, , use domainclasspropertycomparator in gsp-s. scaffold templates collections.sort() on default comparator, can use explicit one.

the absence of hibernate might cause: without it, domainclasspropertycomparator won't work, , grails uses simpledomainclasspropertycomparator - i'm looking @ defaultgrailstemplategenerator.groovy

you can, sure, provide comparator compare order of declared fields.

edit:

for example, after installing scaffolding have file <project root>\src\templates\scaffolding\edit.gsp. inside, there such lines:

props = domainclass.properties.findall{ ... } collections.sort(props, comparator. ... ) 

where comparator variable provided grails scaffolding. can do:

props = ... collections.sort(props, new propcomparator(domainclass.clazz})) 

where propcomparator like

class propcomparator implements comparator {     private class clazz     propcomparator(class clazz) { this.clazz = clazz }      int compare(object o1, object o2) {         clazz.declaredfields.findindexof{it.name == o1}            - clazz.declaredfields.findindexof{it.name == o2}     }  } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -