package com.vst.webapp.action;
import java.util.List;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.beanutils.BeanUtils;
import com.vst.Constants;
import com.vst.model.DefectRecomendation;
import com.vst.service.DefectRecomendationManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class DefectRecomendationController implements Controller {
private final Log log = LogFactory.getLog(DefectRecomendationController.class);
private DefectRecomendationManager defectRecomendationManager = null;
public void setDefectRecomendationManager(DefectRecomendationManager defectRecomendationManager) {
this.defectRecomendationManager = defectRecomendationManager;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'handleRequest' method...");
}
if (request.getParameter("edited") != null) {
request.setAttribute("addition", "?edited=1");
}
String pageNumber = request.getParameter("d-2568331-p");
if (pageNumber != null) {
request.setAttribute("pageNumber", "d-2568331-p=" + pageNumber);
}
DefectRecomendation defectRecomendation = new DefectRecomendation();
// populate object with request parameters
BeanUtils.populate(defectRecomendation, request.getParameterMap());
if (request.getParameter("delete") != null) {
String defectRecomendationId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
boolean hasFatalError = false;
try {
defectRecomendationManager.removeDefectRecomendation(defectRecomendationId);
request.setAttribute("message", bundle.getString("defectRecomendation.deleted"));
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
List defectRecomendations = defectRecomendationManager.getDefectRecomendations(defectRecomendation);
return new ModelAndView("defectRecomendationList", Constants.DEFECTRECOMENDATION_LIST, defectRecomendations);
}
}