Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about grails filters

Tags:

grails

Basically I have 2 questions regarding grails filters.

  1. According to grails documentation you can do something like below in a filter
if (userId != paramsUserId) {
    flash.message = "You can only modify yourself"
    redirect(action: 'list')
    return false
}

If the above condition is true then how will the return statement get executed ?

  1. Can I have a redirect in my filter to a some action which also has a redirect ?
like image 563
user190982 Avatar asked Jun 05 '10 19:06

user190982


1 Answers

1 - Returning false from a filter prevents further filters (and the action if it's in a before filter) from executing. The browser would get the 302 redirect and go to the 'list' method that you've asked to redirect to.

http://grails.org/doc/2.3.7/guide/single.html#filterTypes

2 - yep. redirecting to something else that redirects is fine. It really doesn't matter to the browser. If you watch it in firebug, you'll see what a redirect really is. When you redirect the browser receives a response with an HTTP status code of 302 ("Found"), this response also includes the url that the browser should request next (the thing you're redirecting to, i.e. the url for the "list" method in the example above). The browser then requests that url and it behaves as if it were the first request.

This is why flash scope is so useful, things in flash scope live until the next request, so they span redirects.

like image 128
Ted Naleid Avatar answered Oct 29 '22 15:10

Ted Naleid