Package com.vst.webapp.action

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

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.DocumentType;
import com.vst.service.DocumentTypeManager;
import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

public class DocumentTypeFormController extends BaseFormController {
    private DocumentTypeManager documentTypeManager = null;

    public void setDocumentTypeManager(DocumentTypeManager documentTypeManager) {
        this.documentTypeManager = documentTypeManager;
    }

    public DocumentTypeFormController() {
        setCommandName("documentType");
        setCommandClass(DocumentType.class);
    }

    protected Object formBackingObject(HttpServletRequest request)
            throws Exception {
        String documentTypeId = request.getParameter("documentTypeId");
        DocumentType documentType = null;

        if (!StringUtils.isEmpty(documentTypeId)) {
            documentType = documentTypeManager.getDocumentType(documentTypeId);
        } else {
            documentType = new DocumentType();
        }

        return documentType;
    }

    public ModelAndView onSubmit(HttpServletRequest request,
                                 HttpServletResponse response, Object command,
                                 BindException errors)
            throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'onSubmit' method...");
        }

        DocumentType documentType = (DocumentType) command;
        boolean isNew = (documentType.getDocumentTypeId() == null);
        Locale locale = request.getLocale();

        if (request.getParameter("delete") != null) {
            documentTypeManager.removeDocumentType(documentType.getDocumentTypeId().toString());

            saveMessage(request, getText("documentType.deleted", locale));
        } else {
            documentTypeManager.saveDocumentType(documentType);

            String key = (isNew) ? "documentType.added" : "documentType.updated";
            saveMessage(request, getText(key, locale));

            if (!isNew) {
                return new ModelAndView("redirect:editDocumentType.html", "documentTypeId", documentType.getDocumentTypeId());
            }
        }

        return new ModelAndView(getSuccessView());
    }
}
TOP

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

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.