"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Controllers/chain.html" (14 Sep 2022, 62032 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:

Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)



Uses flash.html[flash] storage to implicitly retain the model following an HTTP redirect from one action to another.


def shawshankRedemption = new Book(title: 'The Shawshank Redemption')
chain(action: "details", model: [book: shawshankRedemption])



chain(controller*, action, id*, model, params*)


  • uri - The full uri to redirect to (example /book/list, book/show/2)

  • controller (optional) - The controller to redirect to; defaults to the current controller if not specified

  • namespace (optional) - the namespace of the controller to chain to

  • action - The action to redirect to, either a string name or a reference to an action within the current controller

  • id (optional) - The id to use in redirection

  • model - The model to chain to the next action

  • params (optional) - Parameters to pass to the action chained to.

The chain method stores the passed model in flash scope and then performs an HTTP redirect. The model is then restored for the next request. The model that will eventually be passed to the view will be created by starting with the model that was passed to the chain method and then adding to that all of the data that is in the model returned by the next action, which may replace some of the data that was in the model originally passed to the chain method. For example:

def one() {
    chain action: 'two', model: [name: 'Tony', town: 'Birmingham']

def two() {
    [name: 'Anthony', country: 'England']

If a request is sent to the one action, that action chains to the two action which returns a model. The model that is passed to the view would contain [name: 'Anthony', town: 'Birmingham', country: 'England']

The chain method requires either a URI to redirect to or a controller/action/id name combination