diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java b/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java index f6b46f68..818c6541 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java +++ b/spring-js/src/main/java/org/springframework/js/ajax/AjaxHandler.java @@ -24,6 +24,7 @@ import javax.servlet.http.HttpServletResponse; /** * Strategy interface that encapsulates knowledge about a client-side ajax system and how to communicate with that * system. + * * @author Keith Donald */ public interface AjaxHandler { diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AjaxRedirectView.java b/spring-js/src/main/java/org/springframework/js/ajax/AjaxRedirectView.java deleted file mode 100644 index 4687ccfc..00000000 --- a/spring-js/src/main/java/org/springframework/js/ajax/AjaxRedirectView.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.springframework.js.ajax; - -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.web.servlet.View; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.web.servlet.view.RedirectView; - -public class AjaxRedirectView extends RedirectView implements View { - - private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler(); - - public AjaxRedirectView(String redirectUrl, boolean redirectContextRelative, boolean redirectHttp10Compatible) { - super(redirectUrl, redirectContextRelative, redirectHttp10Compatible); - } - - protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String targetUrl, - boolean http10Compatible) throws IOException { - ServletContext context = RequestContextUtils.getWebApplicationContext(request).getServletContext(); - if (ajaxHandler.isAjaxRequest(context, request, response)) { - ajaxHandler.sendAjaxRedirect(context, request, response, targetUrl, false); - } else { - super.sendRedirect(request, response, targetUrl, http10Compatible); - } - } - -} diff --git a/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java b/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java index 8ac873bc..ae5b1722 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java +++ b/spring-js/src/main/java/org/springframework/js/ajax/AjaxUrlBasedViewResolver.java @@ -1,10 +1,38 @@ +/* + * Copyright 2004-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.js.ajax; +import java.io.IOException; import java.util.Locale; +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import org.springframework.web.servlet.View; +import org.springframework.web.servlet.support.RequestContextUtils; +import org.springframework.web.servlet.view.RedirectView; import org.springframework.web.servlet.view.UrlBasedViewResolver; +/** + * View resolver that provides special view resolution for Spring Javascript Ajax requests. + * + * @author Jeremy Grelle + * + */ public class AjaxUrlBasedViewResolver extends UrlBasedViewResolver { /** @@ -25,4 +53,24 @@ public class AjaxUrlBasedViewResolver extends UrlBasedViewResolver { } return super.createView(viewName, locale); } + + private class AjaxRedirectView extends RedirectView implements View { + + private AjaxHandler ajaxHandler = new SpringJavascriptAjaxHandler(); + + public AjaxRedirectView(String redirectUrl, boolean redirectContextRelative, boolean redirectHttp10Compatible) { + super(redirectUrl, redirectContextRelative, redirectHttp10Compatible); + } + + protected void sendRedirect(HttpServletRequest request, HttpServletResponse response, String targetUrl, + boolean http10Compatible) throws IOException { + ServletContext context = RequestContextUtils.getWebApplicationContext(request).getServletContext(); + if (ajaxHandler.isAjaxRequest(context, request, response)) { + ajaxHandler.sendAjaxRedirect(context, request, response, targetUrl, false); + } else { + super.sendRedirect(request, response, targetUrl, http10Compatible); + } + } + + } } diff --git a/spring-js/src/main/java/org/springframework/js/ajax/tiles2/AjaxTilesView.java b/spring-js/src/main/java/org/springframework/js/ajax/tiles2/AjaxTilesView.java index 69989f0c..567b74e0 100644 --- a/spring-js/src/main/java/org/springframework/js/ajax/tiles2/AjaxTilesView.java +++ b/spring-js/src/main/java/org/springframework/js/ajax/tiles2/AjaxTilesView.java @@ -1,3 +1,18 @@ +/* + * Copyright 2004-2008 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.springframework.js.ajax.tiles2; import java.util.HashMap; @@ -22,6 +37,17 @@ import org.springframework.web.servlet.support.JstlUtils; import org.springframework.web.servlet.support.RequestContext; import org.springframework.web.servlet.view.tiles2.TilesView; +/** + * Tiles view implementation that is able to handle partial rendering for Spring Javascript Ajax requests. + * + *
+ * This implementation uses the {@link SpringJavascriptAjaxHandler} by default to determine whether the current request + * is an Ajax request. On an Ajax request, a "fragments" parameter will be extracted from the request in order to + * determine which attributes to render from the current tiles view. + *
+ * + * @author Jeremy Grelle + */ public class AjaxTilesView extends TilesView { private static final String FRAGMENTS_PARAM = "fragments"; @@ -81,4 +107,12 @@ public class AjaxTilesView extends TilesView { } } + public AjaxHandler getAjaxHandler() { + return ajaxHandler; + } + + public void setAjaxHandler(AjaxHandler ajaxHandler) { + this.ajaxHandler = ajaxHandler; + } + } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTilesView.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTilesView.java index 3038d6f5..e38469c1 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTilesView.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/FlowAjaxTilesView.java @@ -20,11 +20,23 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.springframework.js.ajax.SpringJavascriptAjaxHandler; import org.springframework.js.ajax.tiles2.AjaxTilesView; import org.springframework.webflow.execution.RequestContext; import org.springframework.webflow.execution.RequestContextHolder; import org.springframework.webflow.execution.View; +/** + * Tiles view implementation that is able to handle partial rendering for Spring Javascript Ajax requests. + * + *
+ * This implementation uses the {@link SpringJavascriptAjaxHandler} by default to determine whether the current request
+ * is an Ajax request. On an Ajax request for an active flow execution, the fragments set by a {@code