简体   繁体   English

Grails Webflow:操作或过渡状态之外的访问流范围

[英]Grails Webflow: Access flow scope outside of action or transition states

I want to call a subflow where the controller is not known. 我想在不知道控制器的地方调用子流。 It is passed in parameters to beginFlow and I save that in flow scope. 它在参数中传递给beginFlow,我将其保存在流作用域中。 Inside goToForm I'd like to call use the controller that is saved in flow.theController. 在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')
    }
}

As discussed on the user list, it appears that this isn't possible directly, as the subflow name has to be known at the time when the flow structure is being built (at application startup). 如用户列表中所述,这似乎不可能直接实现,因为在构建流结构时(在应用程序启动时)必须知道子流名称。 But since the flow definition DSL is Groovy code you can do something like this: 但是由于流定义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')
    }
}

The listOfControllers could be a static somewhere, or you could possibly do something like this at the top of the flow definition listOfControllers可能是静态的,或者您可以在流定义的顶部执行类似的操作

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

to enumerate all the controllers in the application that define a startFlow. 枚举应用程序中定义startFlow的所有控制器。 You might need a def grailsApplication in your class, I always forget which places in Grails have it available by default and which don't... 您可能需要在类中使用def grailsApplication ,我总是忘记默认情况下Grails中的哪些位置可用,而哪些地方不可用...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM