我有一个 gsp 模板,其中创建视图的数据通过控制器传递。
def create = {
def bookInstance = new Book()
bookInstance .properties = params
def map = getDefaultValues()
render(template: "create", model: [bookInstance : bookInstance ,
title: map.title,
somelist: somelist
....])
gsp模板
<g:select optionKey="id" from="${somelist}" name="somelist.id" value="${bookInstance ?.somelist?.id}" noSelection="['null': '']"></g:select>
现在,在 save 方法中,如果有错误,它返回当前填充和验证的实例(默认脚手架实现)
render(template: "create", model: [bookInstance : bookInstance ])
但是 gsp 中的字段(从保存操作呈现的错误页面)是空的。我可以看到原因,因为它看起来是 中的值"${somelist}"
,但它没有用于保存方法。我是否只需要在 gsp 中检查 null 并使用可用的任何地图或任何更好的方法(在保存方法中传递所有地图不是一个选项)..
提前谢谢..