zoukankan      html  css  js  c++  java
  • ofbiz进击 第二节。 control 理解与创建

    首先要说的是,学习ofbiz,要去http://ofbiz.apache.org/官网里面,去看右边菜单里   Management Apps  的例子,然后找到类似的页面,去看调用的源码方法。

    contoller里面定义了url的action 跳转,类似structs的功能。

    <request-map uri="EditQuoteTermItem">
      <security auth="true" https="true"/>
      <response name="success" type="view" value="EditQuoteTermItem" save-last-view="true"/>
    </request-map>

    如果是这样的结构,就代表直接跳转,如果要加执行判断方法。

    <request-map uri="updatesplit">
      <security https="true" auth="true"/>
      <event type="service" invoke="assignItemShipGroup"/>    或者   <event type="java" path="org.ofbiz.product.product.ProductSearchSession" invoke="clearSearchOptionsHistoryList"/>
      <response name="success" type="view" value="splitship"/>
      <response name="error" type="view" value="splitship"/>
    </request-map>

    在event标签中,如果type为service 则表明调用的是service的方式去执行方法。(service的名称在全局都必须是唯一的,所以调用的是service的方法,就直接写service方法名就好。该文件定义在serviceDef文件夹下,命名规则为service_xxxx.xml, service的s为小写),service服务里面定义的service又分为两种,一种就是engine为simple的方式,这种方式一般都用在单表内的操作,在invoke中定义为create 还是delete 就能实现对单个对象的操作了。但是在大多数的情况下, 都会使用engine类型为simple的方式,这种方式需要在调用定义simple Method的文件,一般这种文件都会定义在script下面,(一般来说在ofbiz中这类相关的语法都已经帮我们写好了。所以,只需要找到类似的页面,然后调用相关的service就好了)

    如果type为java,path代表的是类的路径,invoke为java类中定义的方法。

    在java类中,最重要的几个对象

    1   Delegator delegator = (Delegator) request.getAttribute("delegator");   delegator这个对象就是用来调用findOne findList等方法执行查询功能的对象。(顺带说一句,ofbiz里面的这种方式,个人感觉类似ibatis等 ORM(对象关系映射)的持久层框架。

    2   Map<String,Object> params = UtilHttp.getParameterMap(request); 获取页面参数

    3   GenericValue orderHeaderEntity = null; 定义model对象

    4   LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");  retrunMap = dispatcher.runSync("createReturnHeader", persistMap);   用来调用service服务

    5   

    ModelService modelService = null;
     try {
     modelService = dispatcher.getDispatchContext().getModelService("createReturnHeader");
     } catch (GenericServiceException e) {
     String errMsg = "Error getting model service for serviceName, 'createReturnHeader'. " + e.toString();
     Debug.logError(errMsg, module);
     request.setAttribute("_ERROR_MESSAGE_", "<li>" + errMsg + "</li>");
     return "error";
     }
     Map<String, Object> persistMap = modelService.makeValid(orderHeaderEntity, ModelService.IN_PARAM);

    通过modelService服务,然后按照该过程调用,会自动根据要调用的service服务,将对应的实体对象传入到参数里面,就能够获取service中存在于对象中所需要的所有的参数。

    6

    EventFactory.runRequestEvent(request, response, "makeQuickReturn");   通过这样的写法,可以在Java类中,直接调用control中定义的url链接。

  • 相关阅读:
    vmware ubuntu 异常关机无法连接到网络
    Speed up GCC link
    常用的一些解压命令
    Log4j 漏洞复现
    Test Case Design method Boundary value analysis and Equivalence partitioning
    CCA (Citrix Certified Administrator) exam of “Implementing Citrix XenDesktop 4”
    What is Key Word driven Testing?
    SAP AGS面试小结
    腾讯2013终端实习生一面
    指针的引用
  • 原文地址:https://www.cnblogs.com/wangqc/p/ofbiz_control.html
Copyright © 2011-2022 走看看