开发者

Grails controllers pass parameters

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 confere开发者_JS百科nce 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 ?


I think the problem may be, that you are calling update action by submitting form (I suppose). Maybe you are not passing temp value from that form? You can do it by embedding temp as hidden input field into form, or apply it to url by param attribute on form tag.

Using hidden field it might be something like this (in your view file):

<g:form controller="somecontroller" action="update">
  (...)
  <g:hiddenField name="temp" value="${temp}" />
  (...)
</g:form>

Using params attribute:

<g:form controller="somecontroller" action="update" params="[temp : temp]">
  (...)
</g:form>

I didn't test any of these so there might be some issues, especially in the second approach.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜