1

I am trying to edit grails scaffolding template to create individual fields in create.gsp and edit.gsp

If I add following in create.gsp

<%
        def d = new grails.core.GrailsDomainClass (collegeapplication.Student.class)
        d.persistentProperties.each {
            %>
    ${it}
    <%
        }
    %>

I get unable to resolve class grails.core.GrailsDomainClass For that matter I am not able to load any of my domain class using any of the common methods listed at Groovy way to dynamically instantiate a class from String or at Get domain class field names

Any ideas?

The end result I want is instead of <f:all bean="parentsInfomormation"/> I want to the generate-all command to generate <f:field bean="person" property="name"/> for each property

Community
  • 1
  • 1
Sap
  • 5,197
  • 8
  • 59
  • 101
  • Why don't you try `def domainClass = grailsApplication.getDomainClass(collegeapplication.Student.class)`? – Vinay Prajapati Jan 03 '16 at 12:21
  • @VinayPrajapati how do I get instance of grailsApplication? I don't think it would be available anyways while running generate-all command. – Sap Jan 03 '16 at 12:27
  • you get it by default on gsp page. On templates you can use it without any issues. Try it out or If you need complete solution all together I may paste it as answer. :) – Vinay Prajapati Jan 03 '16 at 12:52
  • @VinayPrajapati it says no such property grailsApplication. Had already tried it. – Sap Jan 03 '16 at 14:18
  • May be http://stackoverflow.com/questions/9868845/grails-templates-scaffolding-controller?rq=1 could help you! – Vinay Prajapati Jan 04 '16 at 05:12
  • @VinayPrajapati I don't think it would work, looking at the date this is pre grails 3.0 where generate template was totally different – Sap Jan 04 '16 at 14:43

1 Answers1

1

With scaffolding plugin in grails 3.x, it's not possible to do what you are trying to achieve. While generating templates for domains, scaffolding plugin doesn't load any of the domain class or you can say it doesn't load the grails application.

Scaffolding plugin uses scripts generated by create-script to generate templates.

In Grails 3.x it is not possible to load a Grails application within a code generation script created by the create-script command.

For more info, read this link.

So you have two options:

  1. Create your own scaffolding task using create-command as explained in link given above.
  2. Use the scaffolding plugin and extend FormFieldsTagLib to define a custom behaviour for <f:all bean=""/> tag.
Sandeep Poonia
  • 2,158
  • 3
  • 16
  • 29