Dave Shuck
Dave Shuck

Reputation: 563

Grails scaffolding - define excludedProperties in the controller action?

Every reference to excluding properties from Grails scaffolded views revolves around adding them to the excludedProperties in the create.gsp and edit.gsp. Is it possible, and not unwise, to define excluded properties in the controller action rather than in the gsp?

Upvotes: 2

Views: 1382

Answers (1)

Todd
Todd

Reputation: 1882

If you want to keep a field from showing up in the scaffolded views, you actually do it by modifying the domain class's constraints closure. For example:

class Book {
   String name
   Integer hideMe

   static constraints = {
       name blank:false
       hideMe display:false
   }
}

By adding "display:false" to the constraints for hideMe, it will prevent it from even showing on ANY of the scaffolded views. You can also set editable, password, format, etc to further control the ones that do show up. Take a look at the Grails documentation on constraints for more info (look at the bottom of this page: http://grails.org/doc/latest/ref/Constraints/Usage.html )

Upvotes: 4

Related Questions