【问题标题】:Grails Webflow: Access flow scope outside of action or transition statesGrails Webflow:访问动作或转换状态之外的流范围
【发布时间】:2012-06-23 19:05:48
【问题描述】:

我想调用一个控制器未知的子流。它在参数中传递给 beginFlow,我将其保存在流范围内。在 goToForm 中,我想调用保存在 flow.theController 中的控制器。


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')
    }
}

【问题讨论】:

    标签: grails spring-webflow


    【解决方案1】:

    正如用户列表中所讨论的,这似乎无法直接实现,因为在构建流结构时(在应用程序启动时)必须知道子流名称。但由于流定义 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 中哪些地方默认提供,哪些不提供...

    【讨论】:

      猜你喜欢
      • 2010-12-14
      • 1970-01-01
      • 2011-06-13
      • 1970-01-01
      • 2016-11-08
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多