开源电商平台OFBiz第二章第一个应用

来源:互联网 发布:淘宝中车手是做什么的 编辑:程序博客网 时间:2024/04/29 19:42


OFBiz所有的定制化开都要



hot-deploy行。也就是自己开件都要放在hot-deploy文件中。

在我们试着来定制化开自己的一个件。

首先我hot-deploy文件下新建一个名字叫practice的文件hot-deploy\practice),注意个文件名字一定要和我要开件名一

然后hot-deploy\practice路径下ofbiz-component.xml文件,文件内容如下

<?xml version="1.0"encoding="UTF-8"?>
<ofbiz-component name="practice"
        xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="
http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
    <resource-loader name="main"type="component"/>
    <webapp name="practice"
        title="Practice"
        server="default-server"
        location="webapp/practice"
       base-permission="OFBTOOLS,ACCOUNTING"
       mount-point="/practice"/>
</ofbiz-component>

个文件在其他的任何已存在的件中都有,你可以从其他件中拷贝过来然后行修改。

ofbiz-component.xml个文件时负责让OFBiz知道你的源位置,并同构筑ClassPath

resource-loader name点的“name”可以自己起一个任意的名称,但是“type”一定要写成“component”,因只有写成“component”OFBiz才能知道要加载这件。

a) name :- web用的名字。
b) title :-
用的标识,会示在上。
c) server :-
OFBiz知道使用哪个server 
d) base-permission :-
行要求用要有OFBTOOLS限才能使用用。'admin'限,所以我不必建其它新用
e) location :- 个服器上缺省基准路径的位置。
f) mount-point :-
访问资源的URL应该localhost:8080/practice
g) app-bar-display :-
个是OFBiz知道是否示在主航条上,个是公用OFBiz的一部分。

 

web

1:在practice件中建一个"webapp"(hot-deploy/practice/webapp).个目包含所有这组件相关的webapp
2
:在webapp建一个子目命名"practice",个就是我要开webapp名称
(hot-deploy/practice/webapp/practice).
一个件可以附加多个web用。比如在"marketing"件中有两个webapps "marketing" and "sfa"们创建的webapp将按照J2EEWeb准。
3:在你webappWEB-INF(hot-deploy/practice/webapp/practice/WEB-INF)。一个OFBizweb用要有两个配置文件:controller.xmlweb.xmlcontroller.xmlOFBiz访问者来的不同求做不同的事:做什么作和渲染什么面。web.xmlOFBiz什么 (database and business logic access) 对这web用是有效的和如何web相关的事,比如welcome pages,redirects, and error pages.
4
建一个命名"web.xml"(web.xml遵守 j2ee
web
).个文件的内容可以从存在的任意件中拷,比如 /framework/example.需要改的重要<display-name>localDispatcherName mainDecoratorLocation. 

web.xml的内容如下:

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application2.3//EN" "
http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <display-name>Open For Business - PracticeManager</display-name>
    <description>Practice Manager Module of the Open For BusinessProject</description>

    <context-param>
       <param-name>entityDelegatorName</param-name>
       <param-value>default</param-value>
        <description>The Name of theEntity Delegator to use, defined in entityengine.xml</description>
    </context-param>
    <context-param>
       <param-name>localDispatcherName</param-name>
       <param-value>practice</param-value>
        <description>A unique nameused to identify/recognize the local dispatcher for the ServiceEngine</description>
    </context-param>
    <context-param>
       <param-name>mainDecoratorLocation</param-name>
       <param-value>component://practice/widget/CommonScreens.xml</param-value>
        <description>The location ofthe main-decorator screen to use for this webapp; referred to as a contextvariable in screen def XML files.</description>
    </context-param>
    <context-param>
       <param-name>partyDecoratorLocation</param-name>
       <param-value>component://practice/widget/CommonScreens.xml</param-value>
        <description>The location ofthe CommonPartyDecorator screen to use for this webapp; referred to as acontext variable in screen def XML files.</description>
    </context-param>

    <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>/error:/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/main</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>
    <!-- NOTE: not all app servers support mountingimplementations of the HttpSessionActivationListener interface -->
    <!-- <listener><listener-class>org.ofbiz.webapp.control.ControlActivationEventListener</listener-class></listener>-->

    <servlet>
       <servlet-name>ControlServlet</servlet-name>
       <display-name>ControlServlet</display-name>
        <description>Main ControlServlet</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> <!-- in minutes -->
    </session-config>

    <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
       <welcome-file>index.html</welcome-file>
       <welcome-file>index.htm</welcome-file>
    </welcome-file-list>
</web-app>

5建一个命名"controller.xml" (ofbiz webapp控制器使用)的文件。个文件开始是小而简单,但随后我增加功能而快速增

<?xml version="1.0"encoding="UTF-8"?>
<site-conf xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="
http://ofbiz.apache.org/dtds/site-conf.xsd">
    <include location="component://common/webcommon/WEB-INF/common-controller.xml"/>
    <includelocation="component://commonext/webapp/WEB-INF/controller.xml"/>
    <description>Practice Manager Module SiteConfiguration File</description>
    <owner>Copyright 2001-2009 The Apache SoftwareFoundation</owner>      
    <!-- <handler name="screen"type="view"class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/> -->
    <!-- Events to run on every request before security(chains exempt) -->
    <!-- Request Mappings -->
    <errorpage>/error/error.jsp</errorpage>
    <request-map uri="main">
        <security https="true"auth="false"/>
        <responsename="success" type="view" value="main"/>
    </request-map>
    <!-- end of request mappings -->

    <!-- View Mappings-->
    <view-map name="main" type="screen"page="component://practice/widget/PracticeScreens.xml#main"/>
    <!-- end of view mappings -->
</site-conf>

6:移到上一建一个新的目,命名'error'(hot-deploy/practice/webapp/practice/error).
 6.a :
"error"建一个文件.个文件的内容可以取自任意存在的件中,比如example件。错误信息面的位置将被指定在controller.xml文件的开始位置,比如
<errorpage>/error/error.jsp</errorpage> .
你需要建或拷一个/webapp/practice/error/error.jsp向用户显错误信息。
7
:在你的件目practice建一个"widget"(hot-deploy/practice/widget).个目就包含forms, menus, and screens,用来理用界面的。
8
:在"widget"建文件"PracticeScreens.xml".个文件的内容可以取自任意件中,
例如example件。

PracticeScreens.xml的内容如下:

<?xml version="1.0"encoding="UTF-8"?>

<screens xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="
http://ofbiz.apache.org/dtds/widget-screen.xsd">
    <screen name="main">
        <section>
           <widgets>
               <label text="This is first practice"/>
           </widgets>
        </section>
    </screen>
    <screen name="person">
        <section>
           <actions>
               <scriptlocation="component://practice/webapp/practice/WEB-INF/actions/Person.groovy"/>
           </actions>
           <widgets>
            <decorator-screenname="CommonPracticeDecorator"location="${parameters.mainDecoratorLocation}">
             <decorator-section name="body">
              <platform-specific>
               <html>
                <html-templatelocation="component://practice/webapp/practice/Person.ftl">
               </html>
              </platform-specific>
             </decorator-section>
            </decorator-screen>
           </widgets>
        </section>
    </screen>   
</screens>

9在我们这里有基本的元素,检查本流程,不管你的得如何大和复。开始,通过浏览器来发动一个求来看指定的源。求:"localhost:8080/practice/control/main"
1.
OFBiz看到求,首先检查/practice部分。是因在我ofbiz-component.xml文件,我
出我web用的装点是/practice在知道我practice件将理余下的求。 
2. OFBiz将然后看我controller.xml文件。
在我controller.xml文件有request-mapsview-maps。如果它发现一个名字'main'request-map,它将使用相关view-map,如下所述。request-map也能指定一个view或我将会看到的eventservice.如果指定一个view将在the controller.xml 文件中一步找,看是否有在request-map指定值对应view-map
3.在我们继续保持简单,假定所有views到一个type=screen.个情况下,标签指定一个路径到
screen
文件而且一个screen名称示在"#"符号后

10运行你的第一个练习应用。
命令行入下面: java -Xmx256M -jar ofbiz.jar (the -Xmx256M命令程序有足的内存)。然后在浏览器上点击这个地址http://localhost:8080/practice/control/main浏览应该看到出屏幕"This is first practice"

 

0 0
原创粉丝点击