Announcement Announcement Module
Collapse
No announcement yet.
Static closure for web flow action Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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, 06:30 AM.

      Comment


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

        Comment


        • #5
          Actually that works

          Comment

          Working...
          X