Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

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.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
XT AJAX Interceptor Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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.

    Code:
    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;
    		}
    		if(!isAjaxRequest(request)){
    			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 {
    		
    		if(isAjaxRequest(request)){
    			postAjaxHandle(request,response,handler);
    		}
    	}
    	
    	abstract protected void postAjaxHandle(HttpServletRequest request,
    			HttpServletResponse response, Object handler);
        
    	
    	private boolean isAjaxRequest(HttpServletRequest request) {
    		Collection beans = this.applicationContext.getBeansOfType(
    				AjaxInterceptor.class).values();
    		if (beans.size() > 1) {
    			throw new IllegalStateException(
    					"Error: more AjaxInterceptors configured!");
    		} else {
    			AjaxInterceptor interceptor = (AjaxInterceptor) beans.iterator()
    					.next();
    			return interceptor.isAjaxRequest(request);
    		}
    	}
    }
    Last edited by liulei; Sep 19th, 2007, 08:55 PM.

    Comment


    • #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

      Comment


      • #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?

        Comment


        • #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.

          Comment

          Working...
          X