package com.vst.webapp.action;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import com.vst.webapp.action.BaseFormController;
import com.vst.model.SvodDefect;
import com.vst.service.SvodDefectManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
public class SvodDefectFormController extends BaseFormController {
private SvodDefectManager svodDefectManager = null;
public void setSvodDefectManager(SvodDefectManager svodDefectManager) {
this.svodDefectManager = svodDefectManager;
}
public SvodDefectFormController() {
setCommandName("svodDefect");
setCommandClass(SvodDefect.class);
}
protected Object formBackingObject(HttpServletRequest request)
throws Exception {
String svodDefectId = request.getParameter("svodDefectId");
SvodDefect svodDefect = null;
if (!StringUtils.isEmpty(svodDefectId)) {
svodDefect = svodDefectManager.getSvodDefect(svodDefectId);
} else {
svodDefect = new SvodDefect();
}
return svodDefect;
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command,
BindException errors)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("entering 'onSubmit' method...");
}
SvodDefect svodDefect = (SvodDefect) command;
boolean isNew = (svodDefect.getSvodDefectId() == null);
Locale locale = request.getLocale();
if (request.getParameter("delete") != null) {
svodDefectManager.removeSvodDefect(svodDefect.getSvodDefectId().toString());
saveMessage(request, getText("svodDefect.deleted", locale));
} else {
svodDefectManager.saveSvodDefect(svodDefect);
String key = (isNew) ? "svodDefect.added" : "svodDefect.updated";
saveMessage(request, getText(key, locale));
if (!isNew) {
return new ModelAndView("redirect:editSvodDefect.html", "svodDefectId", svodDefect.getSvodDefectId());
}
}
return new ModelAndView(getSuccessView());
}
}