problem with redirection in a grails in a controller.
in Controller:
def function1 = {
... do stuff ...
... go to service ...
redirect(action: "searchName", name: test)
//redirect(action: "searchName", params: [ name: test ])
}
in searchName, there are no parameters. its an empty list.
try the second way of calling the redirect and i get grails exceions (MissingMethodException), for a method that does exist.
there is nothing special that i can see, that is going on.
any help?
EDIT
the MissingMethodException is not on the searchName function, but on a method within the service. this method is there.
if i use the first redirect method, then the service method works correctly, but the redirect to searchName contains empty parameters.
if i switch the redirect method, then the service method no longer works
(with the exception, so it never gets to the redirect). with fully recompiled/cleaned code.
also, searchName is a closure. again, nothing fancy.
grab the name parameter, and work with it.
class MyWierdController {
def function1 = {
... do stuff ...
... go to service ...
String test="blah"
redirect(action: "searchName", name: test)
}
def searchName = {
if (params.name) {
log.info "its there"
} else {
log.info "its not there"
}
}
}
redirect()is a real HTTP redirect. You will have issues, because all your params will be serialized an deserialized and probably you are losing type information (e.g. Date, which will be string after the redirect.The first version will ignore name parameter, since all parameters have to be within
params.Try
Since you did not quoted the parameters, groovy expects them to be a variable and tries to resolve them. Since both are undefined it is becoming
params: [null: null].However I guess, that you are searching for
render(view: "searchName", params: ["name": "test"]), which will not do a HTTP redirect.