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.MaterialClassification;
import com.vst.service.MaterialClassificationManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class MaterialClassificationController implements Controller {
private final Log log = LogFactory.getLog(MaterialClassificationController.class);
private MaterialClassificationManager materialClassificationManager = null;
public void setMaterialClassificationManager(MaterialClassificationManager materialClassificationManager) {
this.materialClassificationManager = materialClassificationManager;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'handleRequest' method...");
}
if (request.getParameter("delete") != null) {
String questionId = request.getParameter("id");
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
boolean hasFatalError = false;
try {
materialClassificationManager.removeMaterialClassification(questionId);
request.setAttribute("message", bundle.getString("materialClassification.deleted"));
} catch (Exception e) {
hasFatalError = true;
}
if (hasFatalError) {
request.setAttribute("errormessage", bundle.getString("commonMistake"));
}
}
MaterialClassification materialClassification = new MaterialClassification();
// populate object with request parameters
BeanUtils.populate(materialClassification, request.getParameterMap());
List materialClassifications = materialClassificationManager.getMaterialClassifications(materialClassification);
return new
ModelAndView("materialClassificationList", Constants.MATERIALCLASSIFICATION_LIST, materialClassifications);
}
}