Grails 3.3.9: Forward copies params

229 Views Asked by At

We're migrating from Grails 2.x to 3.x. I can observe some different behaviour when using the forward function:

class FooController {

    def index() {
        forward controller: 'foo', action : 'bar', params: params
    }

    def bar() {
        render(
                view: "/foo/foo"
        )
    }
}

When calling http://localhost:8080/foo?test=1 and halting in the bar() method I can see that params looks like that:

params = {GrailsParameterMap@11597}  size = 4
 0 = {LinkedHashMap$Entry@11607} "test" -> 
  key = "test"
  value = {String[2]@11612} 
   0 = "1"
   1 = "1"
 1 = {LinkedHashMap$Entry@11608} "controller" -> "foo"
 2 = {LinkedHashMap$Entry@11609} "format" -> "null"
 3 = {LinkedHashMap$Entry@11610} "action" -> "bar"

As you can see the value of test is saved twice as a String[]. This behaviour is different than it used to be in Grails 2.5.6. Is there any way to set a flag to the Grails forward function in order to not get the params passed to the redirect controller?

1

There are 1 best solutions below

2
Mamun Sardar On

I think you don't need to add the param. forward automatically forwards your parameters. It's optional. If you add it, it will duplicate the values. Try with only:

forward controller: 'foo', action : 'bar'