【问题标题】:Variables available in grails templatesgrails 模板中可用的变量
【发布时间】:2016-04-07 03:20:08
【问题描述】:

我正在尝试编辑 grails 脚手架模板以在 create.gsp 和 edit.gsp 中创建单独的字段

如果我在 create.gsp 中添加以下内容

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

我得到unable to resolve class grails.core.GrailsDomainClass 就此而言,我无法使用Groovy way to dynamically instantiate a class from String 中列出的任何常用方法加载我的任何域类 或Get domain class field names

有什么想法吗?

我想要的最终结果是 &lt;f:all bean="parentsInfomormation"/&gt; 我想用 generate-all 命令来生成 &lt;f:field bean="person" property="name"/&gt; 每个属性

【问题讨论】:

  • 你为什么不试试def domainClass = grailsApplication.getDomainClass(collegeapplication.Student.class)
  • @VinayPrajapati 如何获取 grailsApplication 的实例?我认为在运行 generate-all 命令时无论如何它都不可用。
  • 你默认在 gsp 页面上得到它。在模板上,您可以毫无问题地使用它。试试看,或者如果您需要完整的解决方案,我可以将其粘贴为答案。 :)
  • @VinayPrajapati 它说没有这样的属性 grailsApplication。已经试过了。
  • 可能是stackoverflow.com/questions/9868845/…可以帮助你!

标签: grails groovy grails-3.0.10


【解决方案1】:

使用 grails 3.x 中的 scaffolding 插件,无法实现您想要实现的目标。在为域生成模板时,脚手架插件不加载任何域类,或者您可以说它不加载 grails 应用程序。

脚手架插件使用create-script 生成的脚本来生成模板。

在 Grails 3.x 中,无法在一个 由create-script 命令创建的代码生成脚本。

欲了解更多信息,请阅读此link

所以你有两个选择:

  1. 使用create-command 创建您自己的脚手架任务,如上面给出的链接中所述。
  2. 使用脚手架插件并扩展FormFieldsTagLib&lt;f:all bean=""/&gt; 标签定义自定义行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多