0

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?

Erando
  • 811
  • 3
  • 13
  • 27

1 Answers1

1

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'
Mamun Sardar
  • 2,679
  • 4
  • 36
  • 44
  • Yes, that's what I suspected too. But it would be nice to have some documentation about that `forward` function to see if it supports some kind of option parameters... but there's none. – Erando Feb 11 '19 at 07:45
  • unfortunately there no clear doc on that, but you can see the latest implementation or debug locally to see what's going on: https://github.com/grails/grails-core/blob/master/grails-plugin-controllers/src/main/groovy/grails/artefact/controller/support/RequestForwarder.groovy#L64 – Mamun Sardar Feb 11 '19 at 09:21