Results 1 to 5 of 5

Thread: Static closure for web flow action

  1. #1

    Default Static closure for web flow action

    Does anyone know how to define static closure for web flow action so that action could be defined within another groovy class ?

    for instance :

    class GuessController {

    def guessFlow = {

    start {
    action {
    return ElseWhereActions.startAction(some params)
    }
    on("success").to("ask")
    }
    ...
    }

    class ElseWhereActions {

    def static startAction = { ... -> ...}
    }

    I will appreciate any help.

  2. #2
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    There is a standard approach for doing such things:
    Code:
    class GuessController {
    
       def guessFlow = {
          start {
             action {
                def c = ElseWhereActions.startAction.clone()
                c.delegate = delegate
                c.resolveStrategy = resolveStrategy
                return c.call(some params)
             }
          }
       }
    }
    However, be aware that your shared closure won't have access to properties or methods that are dynamically injected into controllers (such as 'log' and 'params'), so you will have to pass those in as arguments.

  3. #3

    Default

    Thanks a lot
    It really helped me

    Nevertheless I added this code in order to handle transition result :


    def guessFlow = {
    start {
    action {
    def c = ElseWhereActions.startAction.clone()
    c.delegate = delegate
    c.resolveStrategy = Closure.DELEGATE_FIRST
    def ret = c.call(params, log)
    if(ret instanceof Map){
    flow.putAll(new LocalAttributeMap(ret))
    return action.success()
    }
    else if (ret instanceof Event){
    return ret
    }
    else {
    return action.result(ret.toString())
    }

    }
    }
    }

    Do you think it is correct or is there a better approach ?
    Last edited by stephane.manciot; Jan 12th, 2011 at 05:30 AM.

  4. #4
    Join Date
    Jun 2010
    Location
    London
    Posts
    304

    Default

    To be honest, I don't know. If that works, great.

  5. #5

    Default

    Actually that works

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •