【问题标题】:displaying bean class items on view - beginner在视图中显示 bean 类项目 - 初学者
【发布时间】:2014-04-23 15:23:15
【问题描述】:

bean 类如下所示:

字符串房子没有 字符串地址 人人

视图是这样的

<g:form action="save">
    <fieldset class="form">
        <g:render template="form" />
    </fieldset>
    <fieldset class="buttons">
        <g:submitButton name="create" class="save"
            value="${message(code: 'default.button.create.label', default: 'Create')}" />
    </fieldset>
</g:form>

根据我在 Grails 中的知识,我认为 &lt;g:render template="form" /&gt; 将提取所有表单属性并显示它。

但我想要做的不是显示Person 的下拉列表,而是显示所有Person 相关字段,例如personNamepersonAge。如何在下面的标签中显示这些字段?

帮助

【问题讨论】:

    标签: grails


    【解决方案1】:

    您对 g:render 的工作方式是正确的,模板部分指的是 GSP,它将查看 bean 值并根据“_form.gsp”中的 html + groovy 标记打印它们(位于您的视图中控制器名称下的文件夹)。

    要更改 Person 域对象的显示方式,只需编辑此“_form.gsp”并取出“select”html 代码 - 使用 bean 的属性值将其替换为 groovy 标记,例如。

    ${beanName.person.personName} //(use the existing code to help workout the bean name etc)
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-18
      • 2015-12-26
      相关资源
      最近更新 更多