Javadoc and polish of Ajax support classes.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <p>
|
||||
* 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.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user