package br.com.senacagil.springmvc.controllers;

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

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

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

public class CustDetailsController extends AbstractCommandController {

	public CustDetailsController() {
		setCommandClass(CustDetailsCommand.class);
	}

	private CustomerDAO customerDAO;

	public void setCustomerDAO(CustomerDAO c) {
		customerDAO = c;
	}

	protected ModelAndView handle(HttpServletRequest req,
			HttpServletResponse resp, Object cmd, BindException ex)
			throws Exception {
		CustDetailsCommand c = (CustDetailsCommand) cmd;
		Customer cust = customerDAO.findById(c.getCustID());
		return new ModelAndView("custdetails", "cust", cust);
	}
}