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

📄 functionmanageaction.java

📁 《JSP网站开发典型模块与实例精讲》一书光盘源码
💻 JAVA
字号:
package org.appfuse.webapp.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.*;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.appfuse.service.FunctionManager;
import org.appfuse.model.Function;
import org.appfuse.webapp.form.*;
import java.util.*;
import org.appfuse.service.*;
import org.appfuse.model.*;

/**
 * @author Administrator
 *
 * 更改所生成类型注释的模板为 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class FunctionManageAction
    extends BaseAction {

    private static Log log = LogFactory.getLog(FunctionManageAction.class);

    public ActionForward delete(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'delete' method...");
        }
        FunctionManager mgr = (FunctionManager) getBean("functionManager");
        FunctionForm functionForm = (FunctionForm) form;
        mgr.removeFunction(functionForm.getFunctionid());
        return list(mapping, form, request, response);
    }

//
//    public ActionForward removemoduleaction(ActionMapping mapping, ActionForm form,
//                                HttpServletRequest request,
//                                HttpServletResponse response) throws Exception {
//        if (log.isDebugEnabled()) {
//            log.debug("entering 'removemoduleaction' method...");
//        }
//        try {
//            ModuleActionManager moduleMgr = (ModuleManager) getBean("moduleManager");
//            int moduleid = Integer.parseInt(request.getParameter("moduleid"));
//            ActionManager actionMgr = (ActionManager) getBean("actionManager");
//            FunctionForm actionForm = (FunctionForm) form;
//            Module module = moduleMgr.getModule(moduleid);
//            Action action = actionMgr.getAction(actionForm.getActionid());
//            module.removeAction(action);
//            moduleMgr.saveModule(module);
//        }catch(Exception es){
//            log.error("int removemoduleaction", es);
//        }
//        return moduleaction(mapping, form, request, response);
//    }
//
//    public ActionForward createmoduleaction(ActionMapping mapping, ActionForm form,
//                                HttpServletRequest request,
//                                HttpServletResponse response) throws Exception {
//        if (log.isDebugEnabled()) {
//            log.debug("entering 'createmoduleaction' method...");
//        }
//        try {
//            ModuleManager moduleMgr = (ModuleManager) getBean("moduleManager");
//            int moduleid = Integer.parseInt(request.getParameter("moduleid"));
//            ActionManager actionMgr = (ActionManager) getBean("actionManager");
//            FunctionForm actionForm = (FunctionForm) form;
//            Module module = moduleMgr.getModule(moduleid);
//            Action action = actionMgr.getAction(actionForm.getActionid());
//            module.addAction(action);
//            moduleMgr.saveModule(module);
//        }catch(Exception es){
//            log.error("int removemoduleaction", es);
//        }
//        return moduleaction(mapping, form, request, response);
//    }

//
//    public ActionForward moduleaction(ActionMapping mapping, ActionForm form,
//                                HttpServletRequest request,
//                                HttpServletResponse response) throws Exception {
//        if (log.isDebugEnabled()) {
//            log.debug("entering 'moduleaction' method...");
//        }
//        ActionManager actionMgr = null;
//        ModuleManager moduleMgr = null;
//        List lst = null;
//        int moduleid = Integer.parseInt(request.getParameter("moduleid"));
//        Module module = null;
//        List actions = null;
//        try {
//            moduleMgr = (ModuleManager) getBean("moduleManager");
//            module = moduleMgr.getModule(moduleid);
//            actionMgr = (ActionManager) getBean("actionManager");
//            lst = actionMgr.getActions(new Action());
//            actions = new ArrayList(lst.size());
//            for (int i = 0; i < lst.size(); i++) {
//                Action a = (Action) lst.get(i);
//                log.debug(a.getActionid() + "#" + a.getActionname());
//                ActionEx b = new ActionEx();
//                b.setAction(a);
//                actions.add(b);
//            }
//            Iterator it = set.iterator();
//            while (it.hasNext()) {
//                Action a = (Action) it.next();
//                log.debug(a.getActionid() + "#" + a.getActionname());
//                for (int i = 0; i < actions.size(); i++) {
//                    ActionEx b = (ActionEx) actions.get(i);
//                    if (a.getActionid() == b.getActionid()) {
//                        b.setIsExist(true);
//                    }
//                }
//            }
//        }
//        catch (Exception es) {
//            log.error("in moduleaction: ", es);
//        }
//        request.setAttribute("actions", actions);
//        request.setAttribute("module", module);
//            log.debug("out of 'moduleaction' method...");
//        return mapping.findForward("moduleaction");
//    }

    public ActionForward list(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'list' method...");
        }
        FunctionManager mgr = null;
        List lst = null;
        try {
            mgr = (FunctionManager) getBean("functionManager");
            lst = mgr.getFunctions(new Function());
        }
        catch (Exception es) {
            log.error("in list: ", es);
        }
        request.setAttribute("functions", lst);
        return mapping.findForward("list");
    }

    public ActionForward save(ActionMapping mapping, ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'save' method...");
        }

        if (isCancelled(request)) {
            return list(mapping, form, request, response);
        }
        FunctionManager mgr = (FunctionManager) getBean("functionManager");
        FunctionForm functionForm = (FunctionForm) form;
        Function function = new Function();
        copyProperties(function, functionForm);
        try {
            mgr.saveFunction(function);
        }
        catch (Exception es) {
            log.error(es);
        }
        return list(mapping, form, request, response);
    }

    public ActionForward update(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'update' method...");
        }
        if (isCancelled(request)) {
            return list(mapping, form, request, response);
        }
        FunctionManager mgr = (FunctionManager) getBean("functionManager");
        FunctionForm functionForm = (FunctionForm) form;
        request.setAttribute("function",
                             mgr.getFunction(functionForm.getFunctionid()));
        return mapping.findForward("update");
    }

    public ActionForward search(ActionMapping mapping, ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response) throws Exception {
        if (log.isDebugEnabled()) {
            log.debug("entering 'search' method...");
        }
        String no = request.getParameter("functionid");
        if (no == null || no.length() < 1) {
            return list(mapping, form, request, response);
        }
        ArrayList list = new ArrayList(1);
        FunctionManager mgr = (FunctionManager) getBean("functionManager");
        try {
            list.add(mgr.getFunction(Integer.parseInt(no)));
        }
        catch (Exception es) {
            log.error(es);
        }
        request.setAttribute("functions", list);
        return mapping.findForward("list");
    }

    public ActionForward unspecified(ActionMapping mapping, ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        return list(mapping, form, request, response);
    }
}

⌨️ 快捷键说明

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