title: Grails Scaffolding Templates - get properties from domain class
body: <p>I am working on my scaffolding templates, more specifically the create.gsp file. I would like to get the properties defined in my class. I saw many posts online on how to do this but none of them seem to work. </p>
  
  <p>Tried the following (<a href="https://stackoverflow.com/questions/9868845/grails-templates-scaffolding-controller">grails templates - scaffolding controller</a>):</p>
  
  <pre><code>&lt;%
      domainClass.properties.each {
          println "    ${it.type} ${it.name}"
      }
  %&gt;
  </code></pre>
  
  <p>Getting the following error when using generate-all:</p>
  
  <pre><code>Error occurred running Grails CLI: No such property: domainClass for class: groovy.lang.Binding
  </code></pre>
  
  <p>Also tried this approach :</p>
  
  <pre><code>&lt;% import grails.persistence.Event %&gt;
  
  &lt;%  
  excludedProps = Event.allEvents.toList() &lt;&lt; 'version' &lt;&lt; 'dateCreated' &lt;&lt; 'lastUpdated'
  persistentPropNames = domainClass.persistentProperties*.name
  
  props = domainClass.properties.findAll { persistentPropNames.contains(it.name) &amp;&amp; !excludedProps.contains(it.name) &amp;&amp; (domainClass.constrainedProperties[it.name] ? domainClass.constrainedProperties[it.name].display : true) }
  Collections.sort(props, comparator.constructors[0].newInstance([domainClass] as Object[]))
  
  for (p in props) {  %&gt;
  
  &lt;g:message code="${domainClass.propertyName}.${prefix}${p.name}.label" default="${p.naturalName}" /&gt;
  
  &lt;% } %&gt;
  </code></pre>
  
  <p>Getting the following error when using generate-all:</p>
  
  <pre><code>Error occurred running Grails CLI: Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): startup failed:
  GStringTemplateScript4.groovy: 2: Unknown type: IMPORT at line: 2 column: 54. File: GStringTemplateScript4.groovy @ line 2, column 54.
     turn { out -&gt; out &lt;&lt; """""";  import gra
  </code></pre>
  
  <p>Am I missing something or is the approach different for Grails 3?</p>
  
  <p>Using Grails Version 3.0.11</p>
  
  <p>I appreciate any help!</p>