The Grail is Eating Properties

Problem: You are developing a Grails application. You are using scaffolding to build out your views and controller actions. Yet for some mysterious reason Grails is not rendering some properties in the views.

Solution: Did you designate some properties as transient? If so, then by default Grails does not generate transient fields in views. To fix this you need to install the template plugin, and change the value of the persistentPropNames variable:

  1. Install the view templates:
    1. grails InstallTemplates
  2. Now open the pertinent templates (list.gsp, show.gsp) in src/templates/scaffolding
  3. Change the line that reads allowedNames = domainClass.persistentProperties*.name to allowedNames = domainClass.properties*.name for each template.
    1. Note you are changing persistentProperties.* to just plain properties.*. This opens the door for Grails to generate fields in your views that include your transient properties.

Thanks to lo_toad for pointing this one out. This solution saved me so much time.

Advertisement

About Brian Schalme
Solution architect with Airspeed Consulting. Current specialty is Java technologies in the system integration space. I've delivered solutions for customers in the financial services, media, manufacturing, aerospace and transportation industries.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: