Suryateja Kosaraju
Suryateja Kosaraju

Reputation: 513

Redirection in Grails Web-flow

I have question regarding redirection in Grails web-flow. I am in a view state which will allow users to enter the answers for a question. On 2 wrong attempts I should be able to re-direct the user to view page from different controller. What i mean is

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

I have tried to redirect from onRender . It was redirecting to the page. But how do I display the error msg on the redirected page. How can i forward the error message from one controller to other??

Upvotes: 3

Views: 1372

Answers (2)

AA.
AA.

Reputation: 4606

Ivo Houbrechts wrote an excelent tutorial about grails webflow:

Webflow defines its own flash scope. Although it has the same semantics as the standard grails flash scope (the main purpose is to store objects only until after the next request), it is a different scope. This means that objects stored in webflow's flash scope are not visible in standard grails actions.

import org.springframework.web.context.request.RequestContextHolder
....
RequestContextHolder.currentRequestAttributes().flashScope.message = "YourMessage"

You can read more here:

http://livesnippets.cloudfoundry.com/docs/guide/

Upvotes: 3

Sergei Shushkevich
Sergei Shushkevich

Reputation: 1376

Flash scope will not work in this case as expected. Try to use another approach to show error. E.g. you can pass parameters with redirect. Or you can throw some exception and check it on rendered page as follow:

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

Upvotes: 0

Related Questions