我正在将参数以及客户obj从 Controller 传递到gsp页面。例如
render(view:"finish", params: params, model:[customer: customer])
finish.gsp使用参数和传递的客户对象打印表单字段。例如
${params.name}
或${customer.name}
。在完成页面上,选择“完成”按钮后,我要传递参数或客户对象值以保存客户对象。所以我在finish.gsp上设置了隐藏字段。 <g:actionSubmit action="save" value="Done" class="button1" params ="${customer}"/>
<g:hiddenField name="kbc" value="${params}" />
</g:form>`
我可以看到
println params.kbc
的保存操作方法的值是[contactBy:email, appointmentDate:Wed Oct 24 14:54:00 CDT 2012, appointmentDate_day:24, appointmentDate_hour:14, sentReminder:on, appointmentDate_month:10, emailAddress:jaimataji@jaimataji.com, lookingFor:0, appointmentDate_year:2012, appointmentDate_minute:54, _action_finish:Next, myGroup:0, _sentReminder:, description:test, name:abc, contactNo:7777777777, action:index, controller:customer]`</b>
但是,当我尝试访问
params.kbc.name
时,抛出错误提示No such property: name for class: java.lang.String
我不知道我要去哪里错了。如果我错了,请纠正我。
最佳答案
我相信params
对象不会尝试解析/转换所传递数据的内部结构。这只是一个http请求参数。因此,您只能有一个String
。
如果需要将String
转换为Map
,则应编写自己的转换器。似乎不是您想要的。
或者,如果需要params.kbc.name
,则可以将其作为<g:hiddenField name="kbc.name" value="${params.name}" />
传递给其他字段。
关于grails - 无法访问 Controller 中的隐藏字段或参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13057044/