dev@jsftemplating.java.net

encoderedirect

From: Senthil Chidambaram <cchidamb_at_sun.com>
Date: Sat, 24 Feb 2007 07:53:12 -0800

Ken,
Could you please review this, and let me know. I've added
encoderedirect() in NavigationHandlers. The diffs are attached with the
src as well.

thx
Senthil


Index: NavigationHandlers.java
===================================================================
RCS file: /cvs/jsftemplating/src/java/com/sun/jsftemplating/handlers/NavigationHandlers.java,v
retrieving revision 1.5
diff -c -r1.5 NavigationHandlers.java
*** NavigationHandlers.java 16 Feb 2007 10:31:10 -0000 1.5
--- NavigationHandlers.java 24 Feb 2007 15:46:09 -0000
***************
*** 36,41 ****
--- 36,44 ----
  
  import javax.faces.component.UIViewRoot;
  import javax.faces.context.FacesContext;
+ import javax.faces.context.ExternalContext;
+
+ import javax.servlet.http.HttpServletResponse;
  
  
  /**
***************
*** 191,196 ****
--- 194,225 ----
          try {
              ctx.getExternalContext().redirect(page);
              ctx.responseComplete();
+ } catch (IOException ex) {
+ throw new RuntimeException(
+ "Unable to navigate to page '" + page + "'!", ex);
+ }
+ }
+
+ /**
+ * <p> This handler encodes URL, and redirects to the given page.</p>
+ *
+ * <p> Input value: "page" -- Type: <code>String</code></p>
+ *
+ * @param context The {_at_link HandlerContext}.
+ */
+ @Handler(id="encoderedirect",
+ input={
+ @HandlerInput(name="page", type=String.class, required=true)
+ })
+ public static void encoderedirect(HandlerContext context) {
+ String page = (String) context.getInputValue("page");
+ ExternalContext ctx = context.getFacesContext().getExternalContext();
+ HttpServletResponse response = (HttpServletResponse)ctx.getResponse();
+ page = response.encodeRedirectURL(page);
+ context.setOutputValue("page", page);
+ try {
+ ctx.redirect(page);
+ context.getFacesContext().responseComplete();
          } catch (IOException ex) {
              throw new RuntimeException(
                  "Unable to navigate to page '" + page + "'!", ex);