2012-06-20 30 views
0

我想調用控制器未知的子流。它通過參數傳遞給beginFlow,並將其保存在流程範圍中。在goToForm裏我想調用保存在flow.theController中的控制器。Grails Webflow:在操作或轉換狀態之外訪問流程範圍


def beginFlow = { 
    enter { 
     action { 
      if (params?.redirectTo != null) { 
       String flow.theController = params.redirectTo 
      } 

      if (flow.theController()) { 
       success() 
      } 
     } 
     on("success").to("beginPage") 
    } 
    beginPage { 
     on('next').to('goToForm') 
    }  
    goToForm { 
        // I'd like this: 
        // subflow(controller: flow.theController, action:'start' 

        // this subflow works, but won't work for all cases 
     subflow(controller: 'AZ_A4', action:'start') 
     on('done').to('showResults') 
     on('notDone').to('beginPage') 
    } 

    showResults { 
     redirect(action: 'results') 
    } 
} 

回答

0

作爲在用戶列表中所討論的,看來這是不可能直接作爲子流名稱具有在當時是已知正在修建的流動結構時(在應用程序啓動) 。但由於流程定義DSL是Groovy代碼,你可以做這樣的事情:

beginPage { 
    on('next').to('selectSubflow') 
} 
selectSubflow { 
    action { 
     return "subflow_${flow.theController}"() 
    } 
    for(subController in listOfControllers) { 
     on("subflow_${subController}").to("subflow_${subController}") 
    } 
} 
for(subController in listOfControllers) { 
    "subflow_${subController}" { 
     subflow(controller:subController, action:'start') 
     on('done').to('showResults') 
     on('notDone').to('beginPage') 
    } 
} 

的listOfControllers可能是一個靜態的某個地方,或者你可能做這樣的事情在流程定義

def beginFlow = { 
    def listOfControllers = grailsApplication.controllerClasses.findAll { 
     it.flows.containsKey('start') 
    }.collect { it.logicalPropertyName } 
    enter { 
     // ... 
頂部

枚舉應用程序中定義startFlow的所有控制器。您可能需要在您的班級中使用def grailsApplication,我總是會忘記Grails中的哪些地方默認可用,哪些不會...

相關問題