categoryhandler.java

来自「使用EJB实现的网上商城」· Java 代码 · 共 56 行

JAVA
56
字号
package com.jdon.estore.web.catalog;

import com.jdon.strutsutil.*;

import javax.servlet.http.HttpServletRequest;
import com.jdon.bussinessproxy.ServiceServerFactory;
import com.jdon.bussinessproxy.EJBDefinition;

import com.jdon.controller.model.Model;
import com.jdon.controller.events.*;

import com.jdon.estore.model.Category;

import com.jdon.estore.catalog.CatalogManagerLocal;
import com.jdon.estore.FrameworkServices;

public class CategoryHandler implements ModelHandler {

  private final static ServiceServerFactory sf = ServiceServerFactory.
      getInstance();


  public ModelForm initForm(HttpServletRequest request) throws Exception{
    return new CategoryForm();
  }

  public Model findModelByKey(String keyValue, HttpServletRequest request) throws Exception{

    CatalogManagerLocal catalogManager = (CatalogManagerLocal) sf.getService(
        FrameworkServices.CatalogEJB, request);
    return catalogManager.getCategoryById(keyValue);
  }

  public void serviceAction(EventModel em, HttpServletRequest request) throws
      java.lang.
      Exception {
    CatalogManagerLocal catalogManager = (CatalogManagerLocal) sf.getService(
        FrameworkServices.CatalogEJB, request);
    try {
      switch (em.getActionType()) {
        case Event.CREATE:
          catalogManager.createCategory(em);
          break;
        case Event.EDIT:
          catalogManager.updateCategory(em);
          break;
        case Event.DELETE:
          catalogManager.deleteCategory(em);
          break;
      }
    } catch (Exception ex) {
      throw new Exception("System operation Error:" + ex);
    }
  }

}

⌨️ 快捷键说明

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