0

I want to be able to define view table headers in domain classes. I thought about creating a transient property called inTable and then iterate through its values in scaffolding template. Here is a transient property:

List inTable=['cardId','fullName','dateOfBirth','sex','bloodGroup','civilStatus','status']

Now How can I get inTable values inside my scaffolding template?

Feras Odeh
  • 9,136
  • 20
  • 77
  • 121

1 Answers1

1
  1. Make it a static field of your domain class.

  2. Take a look at the way regular scaffolding iterates the class properties. (run grails install-templates if you haven't yet)

  3. Access domainClass.getClazz().inTable.

Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91
  • Can I access list methods of inTable like contains?like domainClass.inTable.contains("")? – Feras Odeh Dec 18 '12 at 03:50
  • Absolutely. `domainClass` is a class reference, `.inTable` is a static field - no other magic here. – Victor Sergienko Dec 18 '12 at 09:21
  • I tried your solution and got the following exception: Error executing script GenerateViews: No such property: inTable for class: org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass – Feras Odeh Dec 18 '12 at 17:48
  • I guess this is because I defined inTable as transient? Is there a workaround to solve this as I don't want to persist this value in database. – Feras Odeh Dec 18 '12 at 18:00
  • Yes, `transient` is not static. Make it `static`, it won't be persisted - only instance fields are persisted. – Victor Sergienko Dec 19 '12 at 09:14
  • Now my bad, I missed `domainClass.getClazz()` piece. Updated. `DefaultGrailsDomainClass' is a sort of "artifact descriptor" in Grails, where artifact types are like: controllers, domain classes, taglib and so on. – Victor Sergienko Dec 19 '12 at 09:49