Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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 ?

like image 920
VictorArgentin Avatar asked Jan 19 '23 15:01

VictorArgentin


1 Answers

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.

like image 183
jjczopek Avatar answered Jan 29 '23 23:01

jjczopek