Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
657 views
in Technique[技术] by (71.8m points)

groovy - Variables available in grails templates

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...