1 package org
.codehaus
.groovy
.grails
.web
.metaclass
3 import org
.springframework
.web
.context
.request
.RequestContextHolder
4 import org
.codehaus
.groovy
.grails
.web
.servlet
.mvc
.GrailsWebRequest
5 import org
.codehaus
.groovy
.grails
.commons
.GrailsClassUtils as GCU
6 import grails
.util
.GrailsWebUtil
7 import org
.codehaus
.groovy
.grails
.commons
.*
8 import org
.codehaus
.groovy
.grails
.web
.mapping
.UrlMappingsHolder
9 import org
.codehaus
.groovy
.grails
.web
.mapping
.UrlCreator
12 * Implementation of the chain() method for controllers
14 * @author Graeme Rocher
17 * Created: Jun 2, 2008
22 static invoke(target
, Map args
= [:]) {
23 def controller
= args
.controller ?
: GCU
.getLogicalPropertyName(target
.class.name
,ControllerArtefactHandler
.TYPE
)
24 def action
= args
.action
26 def params
= args
.params ?
: [:]
27 def model
= args
.model ?
: [:]
29 def actionParams
= params
.findAll
{ it
.key?
.startsWith('_action_') }
30 actionParams?
.each
{ params
.remove(it
.key
) }
33 GrailsWebRequest webRequest
= RequestContextHolder
.currentRequestAttributes()
34 def flash
= webRequest
.getFlashScope()
36 def chainModel
= flash
.chainModel
37 if(chainModel
instanceof Map
) {
38 chainModel
.putAll(model
)
41 flash
.chainModel
= model
43 if(action
instanceof Closure
) {
44 def prop
= GCU
.getPropertyDescriptorForValue(target
, action
)
45 if(prop
) action
= prop
.name
47 def scaffolder
= GrailsWebUtil
.getScaffolderForController(controller
, webRequest
)
48 action
= scaffolder?
.getActionName(action
)
52 action
= action?
.toString()
55 def appCtx
= webRequest
.getApplicationContext()
57 UrlMappingsHolder mappings
= appCtx
.getBean(UrlMappingsHolder
.BEAN_ID
)
59 UrlCreator creator
= mappings
.getReverseMapping(controller
, action
, params
)
60 def response
= webRequest
.getCurrentResponse()
62 def url
= response
.encodeRedirectURL(creator
.createURL(controller
,action
, params
, 'utf-8'))
63 response
.sendRedirect url