I am trying to use the model attribute annotation to populate the "nav" variable with my navigation data for use on the jsp.
I am using tiles 2 for my views, by the way, if that makes any difference.
my attribute "nav" cannot be found on the jsp, even though looking at the log file, i can see that the method getNavigation() is called.
Code:@Controller public class ItemController { @Autowired private ItemManager itemManager; @Autowired private NavigationManager navigationManager; @Autowired private MediaUtils mediaUtil; private final Log log = LogFactory.getLog(ItemController.class); private static final int PROMO_SIZE = 4; //how big are the promotions, how many items do they include? @ModelAttribute("nav") //this DOES NOT APPEAR on my JSP!! public List<Navigation> getNavigation(){ log.debug("returning moddel attribute: "+this.navigationManager.getNavigationByGroupName("main")); return this.navigationManager.getNavigationByGroupName("main"); } /** * Maps all nav level 2 requests */ @RequestMapping("/*/*.*") public ModelAndView handleSubCategoryRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String path = request.getServletPath(); int idx=path.lastIndexOf("/"); String navUrl = path.substring(0,idx); String itemSeoName = path.substring(idx+1, path.length() - 5); Navigation selectedNav = navigationManager.getNavigationByURL(navUrl); ModelAndView mav = new ModelAndView("error.404"); log.debug("(detail) nav url:"+navUrl+" nav:"+selectedNav); log.debug("(detail) item seo name:"+itemSeoName); if(selectedNav == null){ mav.setViewName("error.404"); } else if(selectedNav.getNavName().equals("item") && !processItemDetailRequest(selectedNav, mav, itemSeoName)){ //this is a weird if block: if we have an item request, and fail to process it, fail, //otherwise the request is already set up correctly! mav.setViewName("error.404"); } mav.addObject("selectedNav", selectedNav); // mav.addObject("nav", this.navigationManager.getNavigation()); log.debug("finished detail request returning modelandview: "+mav); return mav; //at this point its error.404 } }


Reply With Quote