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

人走茶凉 提交于 2019-12-01 20:04:18

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

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!