Hi John,
I need to make an amendment to my earlier post, do not use the WebRequestInterceptor as its postHandle method does not allow you to check the view because only the ModelMap is available for use. Instead use the HandlerInterceptor interface and implement the postHandle method. Check if the view exists and if it isn't of type RedirectView and the viewname doesn't start with "redirect:", add the reference data. eg.
(sorry if its a bit messy)
Code:
public void postHandle(HttpServletRequest request,
HttpServletResponse response, Object handler,
ModelAndView modelAndView) throws Exception {
boolean isRedirectView = modelAndView.getView() instanceof RedirectView;
boolean isViewObject = modelAndView.getView() == null;
// if the view name is null then set a default value of true
boolean viewNameStartsWithRedirect = (modelAndView.getViewName() == null ? true : modelAndView.getViewName().startsWith(UrlBasedViewResolver.REDIRECT_URL_PREFIX));
if(modelAndView.hasView() && (
( isViewObject && !isRedirectView) ||
(!isViewObject && !viewNameStartsWithRedirect))){
modelAndView.addObject("stuff", "importantStuff");
modelAndView.addObject("moreStuff", "moreImportantStuff");
}
}
(Please note, I have not tried out this code)
You will also need to register each Interceptor with each handler mapper.
I hope this helps
Josh