0
我將params以及客戶obj傳遞到控制器的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:[email protected], 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 obj中看到它? – Tabho
你真的需要所有的領域?你也可以只傳遞'id'字段,然後加載數據庫中的對象 –
順便說一句,有很多隱藏的字段不是一個大問題 –