tags:

views:

57

answers:

1

Hello, One can specify the order of view elements in GSP file by specifying it in the validation block of the corresponding domain class. If the lass is inherited, the parameter of parent class is always displayed first. For eg

class A {

string a
String b

static constraints = {
  b()
  a()
 }
}

class B extends A{
String c
String d
static constraints = {
  d()
  c()
  b()  //parameter from the parent
  a()  //parameter from the parent
 }
}

the order is b,a,d,c. How can I make it d,c,b,a not tampering with gsp.

thanks..

A: 

In the constraints for class A, define the constraints in the order you want them to be displayed:

static constraints = {
    d()
    c()
    b()
    a()
}

Even if there is no constraint, leave the entry with an empty () to create the order. This only works with scaffolding though.

Lloyd Meinholz
Are you sure I can specify the child elements in the parent.. I got missing method exception when tried!! It compiles fine, but runtime gave error.nested exception is org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: No signature of method: b() is applicable for argument types: (java.util.Collections$EmptyMap) values: [[:]]
bsreekanth
You are correct, I misread your example.Another option would be to try domain object inheritance (with the static mapping tablePerHierarchy false). Then set the order in the subclass.
Lloyd Meinholz
It won't be easy for me to test that as it changes my table structure.. even then i doubt it would allow me to order the way I wanted as the only difference I know about tablePerHierarchy is it creates different tables for extended class than using the parent table. i would try if no one respond me in the meantime.. thank you ...
bsreekanth
I tried the subclass idea and it didn't work either. I'm stumped and can only see creating the gsp and modifying it there (that's not really so bad and I've done it before myself).
Lloyd Meinholz
that's true..it isn't that bad.. the disadvantages are, I can't use dynamic scaffolding (at least in the initial stages when the domain classes change frequently). I have to manuall make those changes again when I have to recreate the view files (by domain, or scaffolding template changes).. well, if there is no way, then...
bsreekanth