Grails Web流程中的重定向

时间:2012-05-11 00:07:02

标签: grails spring-webflow grails-2.0 grails-controller

我对Grails web-flow中的重定向有疑问。 我处于视图状态,允许用户输入问题的答案。在2次错误的尝试中,我应该能够重定向用户从不同的控制器查看页面。我的意思是

challengeQuestionOne{
            onRender() {
                //Display question
            }
            on('next') {BuildQuestion command ->
                bindData(flow.recovery,command)
                [return the model to flow]
                if(command.hasErrors()) {
                    flow.command = command
                    return error()
                }
                if(check for status. If doesnot pass){
                    flash.message=message(code:'loginForm.account.locked', default: 'Please Contact Admin.')
                    redirect(controller : "login",action: "login")//how to redirect from here to diff controller
                }                    
                if (//compare answer entered) {

                }
                else{
                   //set status not active
                }

            }.to("challengeQuestionTwo")
            on(Exception).to("error")
            on('cancel').to('finish')                
        }

我试图从onRender重定向。它正在重定向到页面。但是如何在重定向页面上显示错误消息。如何将错误消息从一个控制器转发到其他控制器?

1 个答案:

答案 0 :(得分:0)

在这种情况下,Flash范围不会按预期工作。 尝试使用另一种方法来显示错误。例如。你可以通过重定向传递参数。或者您可以抛出一些异常并在渲染页面上进行检查,如下所示:

<g:if test="${flowExecutionException}">
    <div class="error"><g:message code="loginForm.account.locked"/></div>
</g:if>