⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countryaction.java

📁 一个关于tlms的一个小程序 看看能否帮助到别人
💻 JAVA
字号:
/**
 * =============================================
 * Copyright 2006 szmx
 *
 * Change Revision
 * --------------------------------
 *   Date                Author         Remarks
 *   2006-4-18        Jean.Zhang     Create com.szmx.tlms.supplychain.web.CountryAction
 * =============================================
 */
package com.szmx.tlms.supplychain.web;

import com.szmx.tlms.admin.model.Employee;
import com.szmx.tlms.supplychain.model.Country;
import com.szmx.tlms.supplychain.service.CountryService;
import com.szmx.framework.base.model.Pagination;
import com.szmx.framework.base.web.BaseAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * This function maintains “Country” Chinese information based on English field from SAP.
 * Has List and Update actions.
 * @author Jean.Zhang
 * @since 2006-4-18
 */

public class CountryAction extends BaseAction {


    public ActionForward searchCountry(ActionMapping mapping, ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("Entering 'searchCountry' method");
        }
        DynaActionForm dynaForm = (DynaActionForm) form;
        Map paraMap = new HashMap();
        paraMap.put("countryBean", dynaForm.get("searchBean"));
        Pagination pageObj = new Pagination(request, "pagination");
        CountryService mgr = (CountryService) getBean("countryService");
        Pagination pagination = mgr.getCountry(pageObj, paraMap);
        request.setAttribute("pagination", pagination);

        return mapping.findForward("success");
    }


    /**
     *
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward initUpdateCountry(ActionMapping mapping, ActionForm form,
                                           HttpServletRequest request,
                                           HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {

            log.debug("Entering 'initUpdateCountry' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        Country country = (Country) dynaForm.get("countryBean");

        CountryService service = (CountryService) getBean("countryService");

        country = service.getCountry(country.getId());

        if (country == null) {
            saveActionErrorMessage(request, "err.supplychain.get.noExisted", null);
            return mapping.findForward("failure");
        }
        request.setAttribute("countryBean", country);

        return mapping.findForward("success");
    }

   /**
     * Update one country information
     *
     * @param mapping
     * @param form
     * @param request
     * @param response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward updateCountry(ActionMapping mapping, ActionForm form,
                                       HttpServletRequest request,
                                       HttpServletResponse response)
            throws Exception {
        if (log.isDebugEnabled()) {

            log.debug("Entering 'updateCountry' method");
        }

        DynaActionForm dynaForm = (DynaActionForm) form;
        Country country = (Country) dynaForm.get("countryBean");
        country.populateUpdateBean(getUserId(request));
        CountryService service = (CountryService) getBean("countryService");

        service.save(country);
        dynaForm.set("countryBean", country);
        request.setAttribute("countryBean", country);

        saveActionTripMessage(request, "message.update", null);

        return mapping.findForward("success");
    }

    private Long getUserId(HttpServletRequest request) throws Exception {
        return ((Employee) getLoginedUser(request)).getId();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -