myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bom...@apache.org
Subject svn commit: r1066652 - in /myfaces/tobago/trunk: tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/ tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/ tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/aj...
Date Wed, 02 Feb 2011 22:02:18 GMT
Author: bommel
Date: Wed Feb  2 22:02:18 2011
New Revision: 1066652

URL: http://svn.apache.org/viewvc?rev=1066652&view=rev
Log:
(TOBAGO-969) Support for redirect in the ajax case

Modified:
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
    myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxInternalUtils.java
    myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java?rev=1066652&r1=1066651&r2=1066652&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
(original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/ajax/AjaxUtils.java
Wed Feb  2 22:02:18 2011
@@ -18,13 +18,24 @@ package org.apache.myfaces.tobago.ajax;
  */
 
 
+import org.apache.myfaces.tobago.internal.util.ResponseUtils;
 import org.apache.myfaces.tobago.util.ComponentUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.myfaces.tobago.internal.ajax.AjaxInternalUtils;
 
+import javax.faces.FactoryFinder;
+import javax.faces.application.Application;
+import javax.faces.application.ViewHandler;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.RenderKit;
+import javax.faces.render.RenderKitFactory;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -34,7 +45,9 @@ public class AjaxUtils {
   private static final Logger LOG = LoggerFactory.getLogger(AjaxUtils.class);
 
   public static boolean isAjaxRequest(FacesContext facesContext) {
-    return facesContext.getExternalContext().getRequestMap().containsKey(AjaxInternalUtils.AJAX_COMPONENTS);
+    Map parameterMap = facesContext.getExternalContext().getRequestParameterMap();
+    String ajaxComponentIds = (String) parameterMap.get(AjaxInternalUtils.TOBAGO_PARTIAL_IDS);
+    return ajaxComponentIds != null;
   }
 
   public static void removeAjaxComponent(FacesContext facesContext, String clientId) {
@@ -86,4 +99,37 @@ public class AjaxUtils {
     }
     return added;
   }
+
+  public static boolean redirect(FacesContext facesContext, String url) throws IOException
{
+    if (!isAjaxRequest(facesContext)) {
+      return false;
+    }
+    ResponseWriter writer = facesContext.getResponseWriter();
+    if (writer == null) {
+      RenderKit renderKit = facesContext.getRenderKit();
+      if (renderKit == null) {
+        RenderKitFactory renderFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
+        Application application = facesContext.getApplication();
+        ViewHandler applicationViewHandler = application.getViewHandler();
+        String renderKitId = applicationViewHandler.calculateRenderKitId(facesContext);
+        renderKit = renderFactory.getRenderKit(facesContext, renderKitId);
+      }
+      writer = renderKit.createResponseWriter(((HttpServletResponse)
+              facesContext.getExternalContext().getResponse()).getWriter(), null, null);
+    }
+    ResponseUtils.ensureNoCacheHeader(facesContext);
+    writer.startElement("redirect", null);
+    writer.writeAttribute("url", url, null);
+    writer.endElement("redirect");
+    writer.flush();
+    facesContext.responseComplete();
+    return true;
+  }
+
+  public static void redirect(ServletResponse response, String url) throws IOException {
+    PrintWriter out = response.getWriter();
+    out.print("<redirect url=");
+    out.print(url);
+    out.println("</redirect>");
+  }
 }

Modified: myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxInternalUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxInternalUtils.java?rev=1066652&r1=1066651&r2=1066652&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxInternalUtils.java
(original)
+++ myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/ajax/AjaxInternalUtils.java
Wed Feb  2 22:02:18 2011
@@ -44,6 +44,7 @@ public class AjaxInternalUtils {
   public static final String AJAX_COMPONENTS = AjaxUtils.class.getName() + ".AJAX_COMPONENTS";
 
   private static final String TOBAGO_MESSAGES_CLIENT_IDS = "tobago.messages.clientIds";
+  public static final String TOBAGO_PARTIAL_IDS = "tobago::partialIds";
 
   public static void checkParamValidity(FacesContext facesContext, UIComponent uiComponent,
Class compClass) {
     if (facesContext == null) {
@@ -117,7 +118,7 @@ public class AjaxInternalUtils {
 
   public static Map<String, UIComponent> parseAndStoreComponents(FacesContext facesContext)
{
     Map parameterMap = facesContext.getExternalContext().getRequestParameterMap();
-    String ajaxComponentIds = (String) parameterMap.get("tobago::partialIds");
+    String ajaxComponentIds = (String) parameterMap.get(TOBAGO_PARTIAL_IDS);
     if (ajaxComponentIds != null) {
       if (LOG.isDebugEnabled()) {
         LOG.debug("ajaxComponentIds = \"" + ajaxComponentIds + "\"");

Modified: myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java?rev=1066652&r1=1066651&r2=1066652&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java
(original)
+++ myfaces/tobago/trunk/tobago-extension/tobago-deprecation/src/main/java/org/apache/myfaces/tobago/ajax/api/AjaxUtils.java
Wed Feb  2 22:02:18 2011
@@ -22,6 +22,7 @@ import org.apache.myfaces.tobago.interna
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.servlet.ServletResponse;
 import java.io.IOException;
 import java.util.Map;
 
@@ -124,4 +125,20 @@ public class AjaxUtils {
   public static String encodeJavascriptString(String value) {
     return AjaxInternalUtils.encodeJavaScriptString(value);
   }
+
+  /**
+   * @deprecated Please use org.apache.myfaces.tobago.ajax.AjaxUtils.redirect
+   */
+  @Deprecated
+  public static void redirect(FacesContext facesContext, String url) throws IOException {
+    org.apache.myfaces.tobago.ajax.AjaxUtils.redirect(facesContext, url);
+  }
+
+  /**
+   * @deprecated Please use org.apache.myfaces.tobago.ajax.AjaxUtils.redirect
+   */
+  @Deprecated
+  public static void redirect(ServletResponse response, String url) throws IOException {
+    org.apache.myfaces.tobago.ajax.AjaxUtils.redirect(response, url);
+  }
 }



Mime
View raw message