5

I am trying to use the chain feature to call an other method and render a merged model. This is how I call the chain:

Controller: emailToNotify, Method: sendEmailConfirmation

if (someCommandObject.hasErrors())
                chain(controller: "creditProvider", action: "rank", model: [emailToNotify: epnc, somethingToDisplay: "Boom !!!!"])

This is how my rank method end-up in my creditProvider controller:

Controller: creditProvider, action: rank

render (view: 'simulateResult', model: [bim : bam, boom : bimbamboom])

I do not manage to call ${emailToNotify} or ${somethingToDisplay} from my simulateResult.gsp view.

I have already used chain before in this exact same way, and it was (and still is) working properly.

Any idea why the model is not passed properly to the view ?

Any help most welcome as always. All the best,

Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76

2 Answers2

11

chain only works if the final action returns a Map and not if the final action uses the render call. To get what you are doing to work you'll have to manually merge the implicit variable chainModel with the model you're passing back in to the render.

schmolly159
  • 3,881
  • 17
  • 26
  • 1
    Thank you, you have ended-up 2hours of tracing variables :) Is this written somewhere in the documentation ?? I did not read this there, but maybe I missed it. – Alexandre Bourlier Oct 05 '11 at 16:53
  • 1
    I don't know of any specific documentation on that rule. I don't remember where I first learned it either. – schmolly159 Oct 05 '11 at 17:05
1

I was having the same issue with this and found that one way to get around this is to use the Spring ModelAndView object. From the firstController:

chain(controller: second, action: 'chainedMethod', model: [modelField2: '2'])

Then in the secondController:

import org.springframework.web.servlet.ModelAndView
...
def chainedMethod() {
  return new ModelAndView('/other/view', [modelField1: '1'])
}

This works for me using Grails 2.1.1 so can't speak to how well it works with other versions. Hope that helps other people, had to dig around and try a few different routes before getting this.

dkstyle0
  • 51
  • 2