Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
XT AJAX Interceptor Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • XT AJAX Interceptor

    How to add an interceptor for doAjaxAction and doAjaxSubmit request.

  • #2
    This is my a implements calss.

    abstract public class AjaxRequestInterceptor extends HandlerInterceptorAdapter implements
    		ApplicationContextAware {
    	private ApplicationContext applicationContext;
    	public void setApplicationContext(ApplicationContext applicationContext)
    			throws BeansException {
    		this.applicationContext = applicationContext;
    	public boolean preHandle(HttpServletRequest request,
    			HttpServletResponse response, Object handler) throws Exception {
    		if (WebUtils.isIncludeRequest(request)) {
    			return true;
    			return true;
    		return preAjaxHandle(request,response,handler);
    	abstract protected boolean preAjaxHandle(HttpServletRequest request,
    			HttpServletResponse response, Object handler);
    	 * This implementation is empty.
    	public void postHandle(HttpServletRequest request,
    			HttpServletResponse response, Object handler,
    			ModelAndView modelAndView) throws Exception {
    	abstract protected void postAjaxHandle(HttpServletRequest request,
    			HttpServletResponse response, Object handler);
    	private boolean isAjaxRequest(HttpServletRequest request) {
    		Collection beans = this.applicationContext.getBeansOfType(
    		if (beans.size() > 1) {
    			throw new IllegalStateException(
    					"Error: more AjaxInterceptors configured!");
    		} else {
    			AjaxInterceptor interceptor = (AjaxInterceptor) beans.iterator()
    			return interceptor.isAjaxRequest(request);
    Last edited by liulei; Sep 19th, 2007, 08:55 PM.


    • #3
      When posting code please use [ code][/code ] tags, that way we can decipher your code.

      Read the manual chapter 18 covers XT Modules and chapter 18.3 covers XT Modules AJAX. The tutorial section explains and shows quite extensivly how to set it up and how to use it. Also you don't need to write an Interceptor yourself the XT Modules Ajax provides one.

      You might also want to read the Spring reference guide regarding SpringMVC and Interceptors.
      Last edited by Marten Deinum; Sep 19th, 2007, 05:07 AM. Reason: Added links to reference guides


      • #4
        I mean this is not the org.springmodules.xt.ajax.AjaxInterceptor class.
        I mean how to add an interceptor, the interceptor will intercept doAjaxAction doAjaxSubmit request and will not intercept the general spring MVC request?


        • #5
          Have you READ the links I send you. Also I wonder why reinvent the wheel, but alas. You will first need to intercept the general sprinv mvc request to check what is called.

          Why implement your own mechanism while XT Module it ships with a perfectly working one.