Grails - Controller Circuit and Model Malfunction

I am trying to use the chain function to call another method and create a unified model. So I call chain :

Controller: emailToNotify, method: sendEmailConfirmation

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

This is how my rank method ends up in my creditProvider controller:

Controller: creditProvider, action: rank

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

I am unable to call ${emailToNotify} or ${somethingToDisplay} from my simulateResult.gsp view.

I already used chain before, just like it was (and still is) working correctly.

Any idea why the model is not being correctly passed to the view?

Any help is appreciated, as always. All the best,

+4
source share
2 answers

chain only works if the final action returns a Map , and not if the last action uses the render call. To get what you are doing to work, you will have to manually combine the implicit variable chainModel with the model with which you return to render .

+9
source

I had the same problem with this and found that one way around this is to use the Spring ModelAndView object. From the first controller:

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

Then in the second controller:

 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 I can’t say how well it works with other versions. Hope this helps other people, I had to dig around and try several different routes before getting this.

+1
source

All Articles