Package com.vst.webapp.action

Source Code of com.vst.webapp.action.InsertPipelineSubtypeController

package com.vst.webapp.action;

import com.vst.model.Gost;
import com.vst.model.PipelineSubtype;
import com.vst.service.PipelineSubtypeManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

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

/**
* Created by IntelliJ IDEA.
* User: And Lilia
* Date: 22.04.2009
* Time: 16:35:11
* To change this template use File | Settings | File Templates.
*/
public class InsertPipelineSubtypeController extends BaseFormController {

    PipelineSubtypeManager pipelineSubtypeManager;

    public void setPipelineSubtypeManager(PipelineSubtypeManager pipelineSubtypeManager) {
        this.pipelineSubtypeManager = pipelineSubtypeManager;
    }

    public InsertPipelineSubtypeController() {

        setCommandName("pipeline");
        setCommandClass(PipelineSubtype.class);
    }

    protected Object formBackingObject(HttpServletRequest request) throws Exception {


        if (!isFormSubmission(request)) {
            PipelineSubtype pipelineSubtype = new PipelineSubtype();

            if (request.getParameter("pipelineId") != null) {
                int id = Integer.parseInt(request.getParameter("pipelineId"));
                pipelineSubtype = pipelineSubtypeManager.getPipelineSubtypeById((Integer) id);
            }

            if (request.getParameter("edited") != null) {
                request.setAttribute("addition", "?edited=1");
                pipelineSubtype.setEdited(true);
            }

            return pipelineSubtype;
        }

        return super.formBackingObject(request);
    }

    public ModelAndView onSubmit(HttpServletRequest request,
                                 HttpServletResponse response,
                                 Object command,
                                 BindException errors) throws Exception {

        ModelAndView mav = new ModelAndView(getSuccessView());

        if (request.getParameter("cansel") != null) {
            return new ModelAndView("redirect:/lookPipelineSubtype.html");
        }

        PipelineSubtype pipelineSubtype = (PipelineSubtype) command;

        if (pipelineSubtype.getPipelineId() != null) {
            pipelineSubtypeManager.update(pipelineSubtype);
            if (pipelineSubtype.isEdited()) {

                return new ModelAndView("redirect:updating.html?id=" + pipelineSubtype.getPipelineId() + "&fieldId=" + request.getParameter("fieldId"));
            }
            return new ModelAndView("redirect:/lookPipelineSubtype.html");

        } else {
            pipelineSubtypeManager.insert(pipelineSubtype);
            mav.addObject("pipeline", new PipelineSubtype());
            mav.addObject("result", new Integer(1));
            if (pipelineSubtype.isEdited()) {

                return new ModelAndView("redirect:updating.html?id=" + pipelineSubtype.getPipelineId() + "&fieldId=" + request.getParameter("fieldId"));
            }
            return mav;
        }


    }

}
TOP

Related Classes of com.vst.webapp.action.InsertPipelineSubtypeController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.