Grails 控制器传递参数
我的控制器如下:
def participated = {
def temp = ConferenceUser.get(params.temp)
def prizes = Prizes.findAllByConferenceUser(temp) // find all rooms where current computer is
def subms = Submissions.findAllByConferenceUser(temp) // find all rooms where current computer is
[temp: temp, priz: prizes, subm: subms]
}
但不知何故,当我成功更新会议值时,我想返回到初始页面(已参与),但我不知道如何传回 params.temp 。 (如果我做一个简单的重定向,因为控制器需要 params.temp
,它会给我一个错误,因为我无法使用空对象作为参数搜索奖品。所以,想象我的更新控制器是以下:
def update = {
def saveParamshere = params.temp
...
...
(code here)
...
...
redirect(action: "participated", params: [temp: saveParamshere])
}
此代码不起作用。如何成功返回主页并传入 params.temp
?
My controller is the folowing:
def participated = {
def temp = ConferenceUser.get(params.temp)
def prizes = Prizes.findAllByConferenceUser(temp) // find all rooms where current computer is
def subms = Submissions.findAllByConferenceUser(temp) // find all rooms where current computer is
[temp: temp, priz: prizes, subm: subms]
}
But somehow, when I successfully update a conference value, I wanna go back to the initial page (participated) but I don't know how to pass back the params.temp
. (if I do a simple redirect, as the controller is expecting params.temp
, it will give me an error because I cannot search prizes with a null object as parameter. So, imagine my update controller is the following:
def update = {
def saveParamshere = params.temp
...
...
(code here)
...
...
redirect(action: "participated", params: [temp: saveParamshere])
}
This code isn't working. How can I successfully go back to my main page and pass in params.temp
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题可能是,您正在通过提交表单来调用
update
操作(我想)。也许您没有从该表单传递temp
值?您可以通过将temp
作为隐藏输入字段嵌入到表单中来实现此目的,或者通过表单标记上的param
属性将其应用到 url。使用隐藏字段可能是这样的(在您的视图文件中):
使用
params
属性:我没有测试其中任何一个,因此可能会出现一些问题,特别是在第二种方法中。
I think the problem may be, that you are calling
update
action by submitting form (I suppose). Maybe you are not passingtemp
value from that form? You can do it by embeddingtemp
as hidden input field into form, or apply it to url byparam
attribute on form tag.Using hidden field it might be something like this (in your view file):
Using
params
attribute:I didn't test any of these so there might be some issues, especially in the second approach.
您可以将参数放入闪存范围内,该作用域适用于两个请求,或者将它们放入会话中并以这种方式检索它们。
以下是有关 flash 范围使用的 grails 文档的链接:
Grails - 控制器 - 控制器范围
You could put the params in the flash scope, which lives for two requests, or put them in the session and retrieve them that way.
Here is a link to the grails docs on usage of flash scope:
Grails - Controllers - Controller Scopes