diff --git a/spring-faces/.classpath b/spring-faces/.classpath
index d7e6ebb1..0325fc4d 100644
--- a/spring-faces/.classpath
+++ b/spring-faces/.classpath
@@ -19,12 +19,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/spring-faces/ivy.xml b/spring-faces/ivy.xml
index 752958a5..37b5e841 100644
--- a/spring-faces/ivy.xml
+++ b/spring-faces/ivy.xml
@@ -36,8 +36,8 @@
-
-
+
+
diff --git a/spring-faces/src/main/java/org/springframework/faces/richfaces/RichFacesAjaxHandler.java b/spring-faces/src/main/java/org/springframework/faces/richfaces/RichFacesAjaxHandler.java
index 80f650c6..c2f36c52 100644
--- a/spring-faces/src/main/java/org/springframework/faces/richfaces/RichFacesAjaxHandler.java
+++ b/spring-faces/src/main/java/org/springframework/faces/richfaces/RichFacesAjaxHandler.java
@@ -26,37 +26,47 @@ import javax.servlet.http.HttpServletResponse;
import org.ajax4jsf.context.AjaxContext;
import org.springframework.faces.webflow.FlowLifecycle;
+import org.springframework.js.ajax.AjaxHandler;
import org.springframework.js.ajax.SpringJavascriptAjaxHandler;
+import org.springframework.web.context.support.WebApplicationObjectSupport;
/**
* Ajax handler that works with Rich Faces, allowing support for Web Flow ajax features with the Rich Faces toolkit.
*
* @author Jeremy Grelle
*/
-public class RichFacesAjaxHandler extends SpringJavascriptAjaxHandler {
+public class RichFacesAjaxHandler extends WebApplicationObjectSupport {
- public boolean isAjaxRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response) {
+ private AjaxHandler delegate = new SpringJavascriptAjaxHandler();
+
+ public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
FacesContextHelper helper = new FacesContextHelper();
- if (AjaxContext.getCurrentInstance(helper.getFacesContext(context, request, response)).isAjaxRequest(
- helper.getFacesContext(context, request, response))) {
+ try {
+ if (AjaxContext.getCurrentInstance(helper.getFacesContext(getServletContext(), request, response))
+ .isAjaxRequest(helper.getFacesContext(getServletContext(), request, response))) {
+ return true;
+ } else {
+ return delegate.isAjaxRequest(request, response);
+ }
+ } finally {
helper.cleanup();
- return true;
- } else {
- helper.cleanup();
- return super.isAjaxRequest(context, request, response);
}
}
- public void sendAjaxRedirect(ServletContext context, HttpServletRequest request, HttpServletResponse response,
- String targetUrl, boolean popup) throws IOException {
+ public void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response,
+ boolean popup) throws IOException {
FacesContextHelper helper = new FacesContextHelper();
- if (AjaxContext.getCurrentInstance(helper.getFacesContext(context, request, response)).isAjaxRequest(
- helper.getFacesContext(context, request, response))) {
+ try {
+ if (AjaxContext.getCurrentInstance(helper.getFacesContext(getServletContext(), request, response))
+ .isAjaxRequest(helper.getFacesContext(getServletContext(), request, response))) {
+ helper.cleanup();
+ response.sendRedirect(response.encodeRedirectURL(targetUrl));
+ } else {
+ helper.cleanup();
+ delegate.sendAjaxRedirect(targetUrl, request, response, popup);
+ }
+ } finally {
helper.cleanup();
- response.sendRedirect(response.encodeRedirectURL(targetUrl));
- } else {
- helper.cleanup();
- super.sendAjaxRedirect(context, request, response, targetUrl, popup);
}
}
diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfViewFactory.java b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfViewFactory.java
index 7694f821..983575fc 100644
--- a/spring-faces/src/main/java/org/springframework/faces/webflow/JsfViewFactory.java
+++ b/spring-faces/src/main/java/org/springframework/faces/webflow/JsfViewFactory.java
@@ -35,7 +35,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.ContextResource;
import org.springframework.core.io.Resource;
import org.springframework.faces.ui.AjaxViewRoot;
-import org.springframework.js.ajax.AjaxHandler;
import org.springframework.js.ajax.SpringJavascriptAjaxHandler;
import org.springframework.webflow.context.ExternalContext;
import org.springframework.webflow.execution.RequestContext;
@@ -54,6 +53,8 @@ public class JsfViewFactory implements ViewFactory {
private static final Log logger = LogFactory.getLog(JsfViewFactory.class);
+ private static SpringJavascriptAjaxHandler springJsAjaxHandler = new SpringJavascriptAjaxHandler();
+
private final Expression viewIdExpression;
private final Lifecycle lifecycle;
@@ -136,11 +137,10 @@ public class JsfViewFactory implements ViewFactory {
}
private boolean isSpringJavascriptAjaxRequest(ExternalContext context) {
- // this is not very clean
+ // consider factoring out into external context
if (context.getNativeContext() instanceof ServletContext) {
- AjaxHandler handler = new SpringJavascriptAjaxHandler();
- return handler.isAjaxRequest((ServletContext) context.getNativeContext(), (HttpServletRequest) context
- .getNativeRequest(), (HttpServletResponse) context.getNativeResponse());
+ return springJsAjaxHandler.isAjaxRequest((HttpServletRequest) context.getNativeRequest(),
+ (HttpServletResponse) context.getNativeResponse());
} else {
return false;
}