List of usage examples for org.springframework.web.servlet ModelAndView getViewName
@Nullable
public String getViewName()
From source file:ro.cs.cm.web.common.MultiFormBeanCheckingInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { // at this point the controller has executed and returned a model so lets // go sort out what we need to do. String viewName = this.getViewName(modelAndView.getViewName()); this.logger.debug("Post processing view: " + viewName); // Now get the vector for the view. Vector<K> controllerList = this.getControllers().get(viewName); if (controllerList == null) { this.logger.debug("View is not in list. Exiting."); return;/*from w ww .ja v a 2s.c om*/ } // Loop and create the beans. String beanKey; String cmdName; Object cmdBean; Class cmdClass; boolean sessionBeanFound; boolean modelBeanFound; for (K c : controllerList) { cmdName = c.getCommandName(); cmdClass = c.getCommandClass(); beanKey = c.getClass().getName() + ".FORM." + cmdName; Map<String, Object> model = modelAndView.getModel(); //Look for an establish bean we can use. sessionBeanFound = request.getSession().getAttribute(beanKey) != null; modelBeanFound = model.containsKey(cmdName); //Try and get a reference to an established bean using either //the session bean or model bean. Otherwise create a new one. if (sessionBeanFound) { this.logger.debug("Bean present under id:" + beanKey); cmdBean = request.getSession().getAttribute(beanKey); } else if (modelBeanFound) { this.logger.debug("Bean present in model."); cmdBean = model.get(cmdName); } else { this.logger.debug("Creating new bean."); cmdBean = cmdClass.newInstance(); } //Now put the bean in session and model if not already there. request.getSession().setAttribute(beanKey, cmdBean); model.put(cmdName, cmdBean); } // Done, call the parent. super.postHandle(request, response, handler, modelAndView); }