package br.com.senacagil.springmvc.controllers;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import br.com.senacagil.springmvc.model.Customer;
import br.com.senacagil.springmvc.dao.CustomerDAO;

public class MainController extends AbstractController {
	public ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) {
		List<Customer> customers = customerDAO.findAll();
		/*
		 * view name - used to look-up display JSP via servlet XML
		 * model name - name of data variable for JSPs
		 * model - data from model
		 */
		return new ModelAndView("home", "customers", customers);
	}

	private CustomerDAO customerDAO;

	// called by spring framework
	public void setCustomerDAO(CustomerDAO c) {
		this.customerDAO = c;
	}
}