package foodplanet.web.controller;

import foodplanet.data.dao.CategoryDao;
import foodplanet.data.model.Category;
import foodplanet.data.model.DataModel;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

public class CategoryListController extends AbstractController{
    private static Log log = LogFactory.getLog(CategoryListController.class);
    private CategoryDao catDao;
    private String viewName;
    
    public void setViewName(String name){
        viewName = name;
    }
    
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        log.info("CategoryListController - Handling request for category list.");
        List cats = catDao.findAllCategories();
        
        request.setAttribute("catSize", cats.size());
        request.setAttribute("catList", cats);
        
        return new ModelAndView(viewName);
    }
    
    public void setCategoryDao(CategoryDao dao){
        this.catDao = dao;
    }
    
}
