Basically I have 2 questions regarding grails filters.
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 - 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With