Grails 模式在错误时重用模板
我有一个 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}"
中的值,但它没有在 save 方法中使用。我是否只需要检查 gsp 中的 null 并使用可用的地图,或者任何更好的方法(在保存方法中传递所有地图不是一个选项)..
提前致谢..
I have a gsp template, where the data for create view is passed through the controller.
def create = {
def bookInstance = new Book()
bookInstance .properties = params
def map = getDefaultValues()
render(template: "create", model: [bookInstance : bookInstance ,
title: map.title,
somelist: somelist
....])
the gsp template
<g:select optionKey="id" from="${somelist}" name="somelist.id" value="${bookInstance ?.somelist?.id}" noSelection="['null': '']"></g:select>
now, in the save method, if there is an error, it returns currently populated and validated instance (default scaffold implementation)
render(template: "create", model: [bookInstance : bookInstance ])
But the fields in the gsp (error page rendered from save action) is empty. I could see the reason as it looks the value in "${somelist}"
, but it is not used in save method. Do i just need to check for null in the gsp and use whichever map is available, or any better method (passing all the map in the save method is not an option) ..
thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了..我必须传递与create闭包中相同的映射..我们在create中传递映射的原因是因为我们想覆盖默认列表..仅使用bookInstance中的填充值保留用户选择,但不是所有值。
I figured it out.. I have to pass the same map as was in the create closure .. the reason why we were passing the maps in create is because we wanted to override the default list.. the populated values in bookInstance is only used to preserve the user selection, but not all the values..