4

私の Grails アプリでは、次の (単純化された) Web フローを定義しました。

def registerFlow = {

    start {
        action {RegistrationCommand cmd ->                

            try {
                memberService.validateRegistrationCommandDTO(cmd)

            } catch (MemberException ex) {
                flow.regErrorCode = ex.errorCode
                throw ex
            }
        }

        on("success").to "survey"  // The 'survey' state has been omitted
        on(MemberException).to "handleRegMemberException"
        on(Exception).to "handleUnexpectedException"
    }

    handleRegMemberException {
        action {
            // Implementation omitted
        }
    }

    handleUnexpectedException {
        redirect(controller:'error', action:'serverError')
    }
}

「開始」状態で MemberException がスローされた場合、実行は「handleRegMemberException」状態に進む必要がありますが、そうではありません。フローの定義、またはこれがどのように機能するかについての私の理解に何か問題がありますか?

ありがとう、ドン

4

2 に答える 2

0

フローは期待どおりに動作するはずです。たとえば、サービスの他のエラーなど、フローに何か問題がある可能性がありますが、実際に何が起こっているのかあなたの質問からは明らかではありません。フローがどのように振る舞うと期待するかを言い、次にそれが期待したように振る舞わないと言うが、実際にどのように振る舞うかは言わない。

フローにトレースを追加して、実際に何が起こっているかを確認することをお勧めします。

ちなみに、さまざまなバージョンの grails にはいくつかの既知のバグがあり、grails 1.2-M3 では Webflow が壊れています: http://jira.codehaus.org/browse/GRAILS-5185

あなたがプログラムしたものに似た私のフローは次のとおりです。

class SomeController {

    def index = {           
        redirect(action:'someProcess')          
        }

def someProcessFlow = {

    start{
        action{
            dosome -> 
                println "-> inside start action closure"
            try{
                println "-> throwing IllegalArgumentException"
                throw new IllegalArgumentException()
            }catch(IllegalArgumentException ex){
                println "-> inside catch"
                throw ex
                }
            throw new Exception()
            "success"               
            }
        on("success").to "helloPage"
        on(IllegalArgumentException).to "illegal"
        on(Exception).to "handleException"
        }

    illegal{
        action{             
            println "-> illegal handled"
            "success"
            }
        on("success").to "helloPage"
        }

    handleException{
        action{             
            println "-> generic exception handled"
            "success"
            }
        on("success").to "helloPage"
    }

    helloPage()

    }
}

期待どおりに動作し、出力は次のとおりです。

-> inside start action closure
-> throwing IllegalArgumentException
-> inside catch
2009-11-03 11:55:00,364 [http-8080-1] ERROR builder.ClosureInvokingAction  
- Exception     occured invoking flow action: null
 java.lang.IllegalArgumentException
    at SomeController$_closure2_closure3_closure6.doCall(SomeController:18)
    at java.lang.Thread.run(Thread.java:619)
-> illegal handled
于 2009-11-03T15:07:53.030 に答える
0

私はまだ Groovy と Grails にかなり慣れていませんが、提案があります。おそらく、この問題は、Grails フレームワーク (および Groovy) がチェックされた例外とチェックされていない例外を処理する方法の違いに関係している可能性があります。

MemberException がチェック済みの例外 (Exception を拡張) である場合、クロージャー内にある「スロー」は、Webflow から完全に実行を引き出すように動作する可能性があります。あなたと私はこれで RTFM を行うことができます... ここから私の本棚に Groovy の本が見えます。簡単な答えとして、MemberException を未チェックの例外 (RuntimeException を拡張) に変更し、同じ結果が得られるかどうかを確認します。または、MemberException を RuntimeException にラップすることもできます...

throw new RuntimeException(ex)

于 2009-07-09T00:34:31.127 に答える