【问题标题】:Grails webflow dynamic step nameGrails webflow 动态步骤名称
【发布时间】:2012-06-26 17:57:56
【问题描述】:

我开始使用 Grails web flow 来实现一个向导。

checkStep {

        action {
            User user = springSecurityService.currentUser
            if (springSecurityService.loggedIn){
                def next = wizardService.getNextFlowStep(user)
                switch (next) {
                       case step1: 
                              step1()
                              break
    ...
                 }
         }
         on("step1").to "wizard_step1"
  } // checkStep
 wizard_step1() {
  ...
 }

我想以更优雅的方式编写第一步,以便根据“wizardService”确定下一步。我还希望这些步骤将在运行时确定,以便实际的步骤名称和顺序可以驻留在数据库中。

谢谢

【问题讨论】:

    标签: grails spring-webflow


    【解决方案1】:

    你想使用 groovy 的 dynamic method invocation 来做类似的事情。我不确定这是否真的可以在 webflow 中工作,但它应该看起来像这样......

            def next = wizardService.getNextFlowStep(user); // returns 'step1';
            "${next}"(); // you may have to use 'this."${next}"();'
    

    【讨论】:

    • 使用此解决方案,您仍然需要显式枚举所有 on('foo').to('bar') 选项(如果事件和状态名称遵循某种结构,则可以使用 for 循环来完成)。我认为没有办法解决这个问题,需要在应用程序启动时知道流程的结构(状态和转换)。 This question 谈到了涉及子流的类似情况。
    猜你喜欢
    • 2011-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多