Tuesday, June 10, 2014

Grails: Listing all fields/variables in a Domain/Model

In this example, I assume your domain class name is 'Research' and the full package name is 'com.package.name.Research'

Way 1:

 Research.declaredFields.each{  
      if(!it.synthetic)  
           println it.name  
 }  

Way 2:

 def names = grailsApplication.getDomainClass('com.package.name.Research').persistentProperties.collect {   
           println it.name   
      }  
   
Way 3:

 def Research domainClass = grailsApplication.getGrailsDomainClass('Research')  
 def persistentProperties = domainClass.getPersistentProperties()  
 persisentProperties.each { property ->  
      println property  
 }  
   

No comments:

Post a Comment