You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2014/07/24 08:40:17 UTC
svn commit: r1613015 - in
/myfaces/tobago/trunk/tobago-core/src/main/java/org/apache/myfaces/tobago:
ajax/AjaxUtils.java internal/ajax/AjaxInternalUtils.java
Author: lofwyr
Date: Thu Jul 24 06:40:17 2014
New Revision: 1613015
URL: http://svn.apache.org/r1613015
Log:
TOBAGO-1414: Utility method for AJAX Request detection in non-faces scenario
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
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=1613015&r1=1613014&r2=1613015&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 Thu Jul 24 06:40:17 2014
@@ -27,6 +27,7 @@ import org.slf4j.LoggerFactory;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
+import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
@@ -48,6 +49,10 @@ public final class AjaxUtils {
return AjaxInternalUtils.isAjaxRequest(facesContext);
}
+ public static boolean isAjaxRequest(final ServletRequest request) {
+ return AjaxInternalUtils.isAjaxRequest((Map<String, String>) request.getParameterMap());
+ }
+
public static void removeAjaxComponent(final FacesContext facesContext, final String clientId) {
final Map<String, UIComponent> ajaxComponents = AjaxInternalUtils.getAjaxComponents(facesContext);
if (ajaxComponents != null) {
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=1613015&r1=1613014&r2=1613015&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 Thu Jul 24 06:40:17 2014
@@ -222,11 +222,13 @@ public final class AjaxInternalUtils {
}
public static boolean isAjaxRequest(final FacesContext facesContext) {
- final Map parameterMap = facesContext.getExternalContext().getRequestParameterMap();
- final String ajaxComponentIds = (String) parameterMap.get(AjaxInternalUtils.TOBAGO_PARTIAL_IDS);
- return ajaxComponentIds != null;
+ return isAjaxRequest(facesContext.getExternalContext().getRequestParameterMap());
}
+ public static boolean isAjaxRequest(final Map<String, String> parameterMap) {
+ final String ajaxComponentIds = parameterMap.get(AjaxInternalUtils.TOBAGO_PARTIAL_IDS);
+ return ajaxComponentIds != null;
+ }
public static boolean redirect(final FacesContext facesContext, final String url) throws IOException {
if (!isAjaxRequest(facesContext)) {
@@ -265,7 +267,7 @@ public final class AjaxInternalUtils {
final Writer writer = response.getWriter();
writer.flush(); // is needed in some cases, e. g. TOBAGO-1094
writer.write("{\n \"tobagoAjaxResponse\": true,\n");
- writer.write(" \"responseCode\": 309,\n");
+ writer.write(" \"responseCode\": " + AjaxResponseRenderer.CODE_RELOAD_REQUIRED + ",\n");
writer.write(" \"location\": \"");
writer.write(pathPrefix + facesContext.getViewRoot().getViewId());
writer.write("\"\n}\n");