You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Apache Wiki <wi...@apache.org> on 2008/06/06 12:45:49 UTC

[Tapestry Wiki] Update of "Tapestry5RedirectException" by VilleVirtanen

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Tapestry Wiki" for change notification.

The following page has been changed by VilleVirtanen:
http://wiki.apache.org/tapestry/Tapestry5RedirectException

------------------------------------------------------------------------------
  In Tapestry 3 and 4 it was possible to throw a special kind of exception to redirect to another page. Howard has not implemented this in Tapestry 5 (as of T5.0.5) possibly because of criticism from many people who think (or perhaps read in a book ; - ) that it is misusing exceptions. Anyway, for the pragmatic ...[[BR]]
+ 
+ Comment from 9902468:[[BR]]
+ I personally use this as security measure: If user doesn't have enough rights the exception is great way to be sure that no other code is executed. If the exception carries information where this user should be redirected that's not going to harm anyone, right? =D
  
  Here are some examples of how to use the exception in a page or component:
  {{{
@@ -77, +80 @@

              public void handleRequestException(Throwable exception) throws IOException
              {
                  // check if wrapped
+                 /*
                  Throwable cause = exception;
                  if (exception.getCause() instanceof RedirectException)
                  {
                      cause = exception.getCause();
+                 }
+                 */
+ 
+                 //Better way to check if the cause is RedirectException. Sometimes it's wrapped pretty deep..
+                 int i = 0;
+                 while(true){
+                     if(cause == null || cause instanceof RedirectException || i > 1000){
+                         break;
+                     }
+                     i++;
+                     cause = cause.getCause();
                  }
  
                  // check for redirect

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org