SWF-1367 Add support for JSF 2 Ajax requests, update booking-faces sample (JSF 2 based Ajax, jsr-303 validation), add chained delegation to AjaxHandlers, other miscellaneous improvements
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package org.springframework.js.ajax;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.context.support.WebApplicationObjectSupport;
|
||||
|
||||
public abstract class AbstractAjaxHandler extends WebApplicationObjectSupport implements AjaxHandler {
|
||||
|
||||
private AbstractAjaxHandler delegate;
|
||||
|
||||
public AbstractAjaxHandler(AbstractAjaxHandler delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public final boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
|
||||
if (isAjaxRequestInternal(request, response)) {
|
||||
return true;
|
||||
}
|
||||
if (delegate != null) {
|
||||
return delegate.isAjaxRequest(request, response);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response,
|
||||
boolean popup) throws IOException {
|
||||
if (isAjaxRequestInternal(request, response)) {
|
||||
sendAjaxRedirectInternal(targetUrl, request, response, popup);
|
||||
}
|
||||
if (delegate != null) {
|
||||
delegate.sendAjaxRedirect(targetUrl, request, response, popup);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract boolean isAjaxRequestInternal(HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
protected abstract void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request,
|
||||
HttpServletResponse response, boolean popup) throws IOException;
|
||||
|
||||
}
|
||||
@@ -25,10 +25,12 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Ajax handler for Spring Javascript (Spring.js).
|
||||
*
|
||||
* @see AbstractAjaxHandler
|
||||
*
|
||||
* @author Jeremy Grelle
|
||||
* @author Keith Donald
|
||||
*/
|
||||
public class SpringJavascriptAjaxHandler implements AjaxHandler {
|
||||
public class SpringJavascriptAjaxHandler extends AbstractAjaxHandler {
|
||||
|
||||
/**
|
||||
* The response header to be set on an Ajax redirect
|
||||
@@ -50,7 +52,21 @@ public class SpringJavascriptAjaxHandler implements AjaxHandler {
|
||||
*/
|
||||
public static final String AJAX_SOURCE_PARAM = "ajaxSource";
|
||||
|
||||
public boolean isAjaxRequest(HttpServletRequest request, HttpServletResponse response) {
|
||||
/**
|
||||
* Create a SpringJavascriptAjaxHandler that is not part of a chain of AjaxHandler's.
|
||||
*/
|
||||
public SpringJavascriptAjaxHandler() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SpringJavascriptAjaxHandler as part of a chain of AjaxHandler's.
|
||||
*/
|
||||
public SpringJavascriptAjaxHandler(AbstractAjaxHandler delegate) {
|
||||
super(delegate);
|
||||
}
|
||||
|
||||
protected boolean isAjaxRequestInternal(HttpServletRequest request, HttpServletResponse response) {
|
||||
String acceptHeader = request.getHeader("Accept");
|
||||
String ajaxParam = request.getParameter(AJAX_SOURCE_PARAM);
|
||||
if (AJAX_ACCEPT_CONTENT_TYPE.equals(acceptHeader) || StringUtils.hasText(ajaxParam)) {
|
||||
@@ -60,7 +76,7 @@ public class SpringJavascriptAjaxHandler implements AjaxHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendAjaxRedirect(String targetUrl, HttpServletRequest request, HttpServletResponse response,
|
||||
protected void sendAjaxRedirectInternal(String targetUrl, HttpServletRequest request, HttpServletResponse response,
|
||||
boolean popup) throws IOException {
|
||||
if (popup) {
|
||||
response.setHeader(POPUP_VIEW_HEADER, "true");
|
||||
|
||||
Reference in New Issue
Block a user