tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Tapestry Wiki] Update of "EasyBrowserRedirection" by EnriqueOcanha
Date Thu, 19 Apr 2007 14:14:29 GMT
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 EnriqueOcanha:
http://wiki.apache.org/tapestry/EasyBrowserRedirection

The comment on the change is:
Code update to make it work in Tapestry4

------------------------------------------------------------------------------
   1. Thow a RedirectException
  
  The following extended RedirectException makes this very easy. Thanks to Paul Ferraro for
posting this gem to the mailing list.
- === Example ===
+ === Example (Tapestry3) ===
  {{{
  
  import org.apache.tapestry.IDirect;
@@ -80, +80 @@

  }
  }}} 
  
+ === Example (Tapestry4) ===
+ {{{
+ import java.util.HashMap;
+ import java.util.Map;
+ import org.apache.hivemind.impl.RegistryBuilder;
+ import org.apache.tapestry.IRequestCycle;
+ import org.apache.tapestry.RedirectException;
+ import org.apache.tapestry.engine.IEngineService;
+ import org.apache.tapestry.engine.ILink;
+ import org.apache.tapestry.services.ServiceConstants;
+ 
+ public class TapestryRedirectException extends RedirectException {
+ 
+     public static IEngineService getPageService() {
+         return (IEngineService)RegistryBuilder.constructDefaultRegistry()
+             .getService("tapestry.services.Page",IEngineService.class);
+     }
+ 
+     public static Map getLinkParams(Strink pageName) {
+         Map linkParams=new HashMap();
+         linkParams.put(ServiceConstants.PAGE,pageName);
+         return linkParams;
+     }
+        
+     private static final long serialVersionUID = 4049918285694842678L;
+ 
+     public TapestryRedirectException(String url)
+     {
+         super(url);
+     }
+    
+     public TapestryRedirectException(ILink link)
+     {
+         this(link.getURL());
+     }
+    
+     /**
+      * Use this to redirect the browser to the specified page
+      */
+     public TapestryRedirectException(IRequestCycle cycle, String page) {
+         this(cycle.getEngine().getInfrastructure().getLinkFactory().constructLink(
+                 TapestryRedirectException.getPageService(),false,
+                 TapestryRedirectException.getLinkParams(page),false));
+     }
+   
+ }
+ 
+ }}}
+ 

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


Mime
View raw message