How to reference a grails GSP model variable indirectly e.g. via .get(…)

后端 未结 3 1498
终归单人心
终归单人心 2021-01-19 11:25

I\'m using a GSP for sending out emails based on the MailService plug-in. The sendMail closure passes (amongst others) body(view:..., model:myModel)

I k

相关标签:
3条回答
  • 2021-01-19 11:35

    I've managed it now using ${pageScope.getProperty(...)}.

    0 讨论(0)
  • 2021-01-19 11:36

    There's no 'model' scope or variable. Instead objects in the model map are set as Request attributes to make them available to the GSP. This is a Spring feature which makes it easy to access variables in JSPs using JSTL and since the GSP syntax is very similar to JSTL it works the same way in Grails.

    So you can use this:

    ${request.getAttribute('item'+i)}
    

    to access model variables using dynamic names.

    0 讨论(0)
  • 2021-01-19 11:36

    You can use ${fieldValue(bean: book, field: 'title')}

    See: http://grails.github.io/grails-doc/latest/ref/Tags/fieldValue.html

    0 讨论(0)
提交回复
热议问题