Search code examples
grailsparametersforwardgrails-controller

Grails 3 - forward with filtered params


In my Grails 3 controller have two actions

def one() {
    forward([ action: 'two', params: [ a: 3 ] ])
}

def two() {
    println params
}

When I call /myController/one?a=1, the printed params are

[a:[3, 1], controller:myController, action:two]

Said that I was somehow surprised of this outcome, I proceeded by changing the one action as follows

def one() {
    params.remove('a')
    println params
    forward([ action: 'two', params: [ a: 3 ] ])
}

The two printlns combined showed

[controller:myController, action:one]
[a:[3, 1], controller:myController, action:two]

with the latter again includign both the original a parameter's value and the new custom value.

My question is: is there something I can do to get rid of the original value, without putting ugly workarounds in place (like using a different name for my param)?


Solution

  • I guess this comment from Graeme Rocher settles any doubts about the overall feasibility:

    A forward is supposed to forward all of the origin params [...]

    However there is no way with the way current servlets work to "override" a parameter, the originals are always retained on a forward.