Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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??

like image 421
Suryateja Kosaraju Avatar asked Jun 30 '26 22:06

Suryateja Kosaraju


1 Answers

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/

like image 144
AA. Avatar answered Jul 03 '26 23:07

AA.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!