mgjj 发表于 2015-11-14 08:30:38

Apache OFBIZ快速上手(一)--简单例子

           本篇文章主要介绍简单例子,OFBIZ的其他介绍就先不说了,放在后面的博文中。

1、目录结构

                  



   说明:在hot-deploy目录下建立文件夹learning,为例。注意先把文件扔到hot-deploy目录下再启动服务器。
  



2、创建ofbiz-component.xml文件


            a.作用:创建此文件,负责让OFBIZ知道learning组件的信息,可以参考applications/accounting/ofbiz-component.xml。
            b.内容如下:

<span style=&quot;font-size:18px;&quot;><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<ofbiz-component name=&quot;learning&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:noNamespaceSchemaLocation=&quot;http://ofbiz.apache.org/dtds/ofbiz-component.xsd&quot;>
<resource-loader name=&quot;main&quot; type=&quot;component&quot;/>
<webapp name=&quot;learning&quot;
title=&quot;Learning&quot;
server=&quot;default-server&quot;
base-permission=&quot;OFBTOOLS&quot;
location=&quot;webapp/learning&quot;
mount-point=&quot;/learning&quot;
app-bar-display=&quot;false&quot;/>
</ofbiz-component>
</span>
      说明:第一个节点中name=”learning”,指的是组件名,告诉OFBIZ加载我们自己定义的name组件,这个名字必须唯一,不能与OFBIZ其他组件名相同。

      Webapp节点:
                name: 定义web应用的名字
                  title: 这个是应用的标识,显示在应用工具条中的名字
            server: 让ofbiz知道是哪个server
             location:learning组件指向的webapp的路径,这里用的是相对路径
       mount-point:应用的访问路径
app-bar-display:应用的title是否要显示






3、创建web.xml
           a.路径:${learning/webapp/learning}/WEB-INF
           b.内容:(基本每个web.xml都是一样的,从applications里面拷贝一个过来即可)

<span style=&quot;font-size:18px;&quot;><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN&quot; &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;>
<web-app>
<display-name>learning</display-name>
<description>The First Hello World Application</description>
<context-param>
<param-name>entityDelegatorName</param-name>
<param-value>default</param-value>
</context-param>
<!-- 本地调用名 start 刘腾腾 -->
<context-param>
<param-name>localDispatcherName</param-name>
<param-value>learning</param-value>
</context-param>
<!-- 本地调用名 end 刘腾腾 -->
<!-- 主修饰器位置,值应该与ofbiz-component.xml里的mount-point相匹配    start 刘腾腾 -->
<context-param>
<param-name>mainDecoratorLocation</param-name>
<param-value>component://simple/widget/CommonScreen.xml</param-value>
<description>The location of the main-decorator screen to use for
this webapplreferred to as a context variable in screen
def XML files.</description>
</context-param>
<!-- 主修饰器位置,值应该与ofbiz-component.xml里的mount-point相匹配    end 刘腾腾 -->
<filter>
<filter-name>ContextFilter</filter-name>
<display-name>ContextFilter</display-name>
<filter-class>org.ofbiz.webapp.control.ContextFilter</filter-class>
<init-param>
<param-name>disableContextSecurity</param-name>
<param-value>N</param-value>
</init-param>
<init-param>
<param-name>allowedPaths</param-name>
<param-value>/control:/select:/index.html:/index.jsp:/default.html:/default.jsp:/images:/includes/maincss.css</param-value>
</init-param>
<init-param>
<param-name>errorCode</param-name>
<param-value>403</param-value>
</init-param>
<init-param>
<param-name>redirectPath</param-name>
<param-value>/control/learning</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.ofbiz.webapp.control.ControlEventListener</listener-class>
</listener>
<listener>
<listener-class>org.ofbiz.webapp.control.LoginEventListener</listener-class>
</listener>
<servlet>
<servlet-name>ControlServlet</servlet-name>
<display-name>ControlServlet</display-name>
<description>Main Control Servlet</description>
<servlet-class>org.ofbiz.webapp.control.ControlServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ControlServlet</servlet-name>
<url-pattern>/control/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
</span>



4、创建controller.xml
  
   a.作用:让OFBIZ根据不同的请求去做相应的事。
            b.内容

<span style=&quot;font-size:18px;&quot;><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<site-conf xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;xsi:noNamespaceSchemaLocation=&quot;http://ofbiz.apache.org/dtds/site-conf.xsd&quot;>
<!-- 引入OFBIZ的公共控制配置 ltt -->
<include location=&quot;component://common/webcommon/WEB-INF/common-controller.xml&quot;/>
<description>Practice Component Site Configuration File</description>
<owner>Copyright 2001-2009 The Apache Software Foundation</owner>
<!-- OFBIZ调用该class处理screen中的xml -->
<handler name=&quot;screen&quot; type=&quot;view&quot; class=&quot;org.ofbiz.widget.screen.ScreenWidgetViewHandler&quot;/>
<!-- Request Mappings -->
<request-map uri=&quot;main&quot;>
<security https=&quot;false&quot; auth=&quot;false&quot;/>
<response name=&quot;success&quot; type=&quot;view&quot; value=&quot;main&quot;/>
</request-map>
<!-- end of request mappings -->
<!-- View Mappings -->
<view-map name=&quot;main&quot; type=&quot;screen&quot; page=&quot;component://simple/widget/SimpleScreens.xml#main&quot;/>
<!-- change the path to the following if the above doesn't work for you -->
<!-- end of view mappings -->
</site-conf>
</span>



5、简单页面
  
     a. 路径:${learning/widget}
           b. 建LearningScreen.xml

<span style=&quot;font-size:18px;&quot;><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?>
<Screens xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;http://www.ofbiz.org/dtds/widget-screen.xsd&quot;>
<screen name=&quot;main&quot;>
<section>
<widgets>
<label text=&quot;===========liutengteng=======is a good girl!========&quot;/>
</widgets>
</section>
</screen>
</Screens></span>




6、运行结果
  
            a.地址   http://localhost:8080/learning/control/main
            b. 效果

  



7、总结
        这是一个简单的OFBIZ的入门小例子,通过一些配置文件,就将我们的系统搭起来了,很快捷,项目的加载部署也很快,灵活配置。下面博文将持续介绍OFBIZ。
  



版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: Apache OFBIZ快速上手(一)--简单例子