package com.vst.webapp.action;
import com.vst.model.PipelineSubtype;
import com.vst.model.Thickness;
import com.vst.service.ThicknessManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.multipart.support.ByteArrayMultipartFileEditor;
import org.springframework.beans.propertyeditors.CustomNumberEditor;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 13.05.2009
* Time: 17:02:50
* To change this template use File | Settings | File Templates.
*/
public class InsertThicknessController extends BaseFormController {
ThicknessManager thicknessManager;
public void setThicknessManager(ThicknessManager thicknessManager) {
this.thicknessManager = thicknessManager;
}
public InsertThicknessController() {
setCommandName("thickness");
setCommandClass(Thickness.class);
}
protected Object formBackingObject(HttpServletRequest request) throws Exception {
if (!isFormSubmission(request)) {
Thickness thickness = new Thickness();
if (request.getParameter("thicknessId") != null) {
int id = Integer.parseInt(request.getParameter("thicknessId"));
return thicknessManager.getThicknessById((Integer) id);
}
if (request.getParameter("edited") != null) {
request.setAttribute("addition", "?edited=1");
thickness.setEdited(true);
}
return thickness;
}
return super.formBackingObject(request);
}
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) {
ModelAndView mav = new ModelAndView(getSuccessView());
if (request.getParameter("cansel") != null) {
return new ModelAndView("redirect:/lookThickness.html");
}
Thickness thickness = (Thickness) command;
if (thickness.getThicknessId() != null) {
thicknessManager.update(thickness);
if (thickness.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + thickness.getThicknessId() + "&fieldId=" + request.getParameter("fieldId"));
}
return new ModelAndView("redirect:/lookThickness.html");
} else {
thicknessManager.insert(thickness);
if (thickness.isEdited()) {
return new ModelAndView("redirect:updating.html?id=" + thickness.getThicknessId() + "&fieldId=" + request.getParameter("fieldId"));
}
mav.addObject("thickness", new Thickness());
mav.addObject("result", Integer.valueOf(1));
return mav;
}
}
}