[OFBiz] Hello World

创建第一个应用

1. 在hot-deploy目录下创建子目录, 命名为"practice"。这个目录名匹配我们要创建的组件名。

 

2. 在hot-deploy/practice路径下创建ofbiz-component.xml文件,填入下面的内容。

<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" 
       base-permission="OFBTOOLS" 
       location="webapp/practice" 
       mount-point="/practice" 
       app-bar-display="false"/> 
</ofbiz-component> 
 
   ofbiz-component.xml说明:

      A. ofbiz-component.xml文件是负责让OFBiz知道资源的位置,同时让你加入到classpath中

     B. 'resource-loader name'可以是任意字符串。这里我们设置为'main',这个'type'告诉OFBiz我们将开始装载一个组件

     C. <webapp>标签中的属性说明如下:

         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知道是否显示在主应用导航条上

 

3. 在practice组件中创建一个'webapp'目录(hot-deploy/practice/webapp),这个目录包含所有这个组件相关的webapp目录

 

4. 在webapp目录下创建一个子目录命名为'practice',这个就是我们要开发的webapp名称(hot-deploy/practice/webapp/practice)一个组件可以附加多个web应用

 

5. 在webapp下创建WEB-INF目录(hot-deploy/practice/webapp/practice/WEB-INF),一个OFBiz 的web 应用要有两个配置文件:controller.xml 和web.xml 。这controller.xml 告诉 OFBiz 从访问者来的不同请求做不同的事:做什么动作和渲染什么页面。

web.xml 告诉 OFBiz 什么资源  (database and business logic access)  对这个web 应用是有效的和如何处理 web 相关的事,比如 welcome pages, redirects, and error pages 。.


 

6. 创建一个命名为'web.xml'的文件,这个文件的内容可以从存在的任意组件中拷贝需要更改的重要指是<display-name>、localDispatcherName和mainDecoratorLocation

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<web-app>
    <display-name>Practice</display-name>
    <description>Example Application of the Open For Business Project</description>

    <context-param>
        <param-name>webSiteId</param-name>
        <param-value>EXAMPLE</param-value>
        <description>A unique ID used to look up the WebSite entity</description>
    </context-param>
    <context-param>
        <param-name>localDispatcherName</param-name><param-value>practice</param-value>
        <description>A unique name used to identify/recognize the local dispatcher for the Service Engine</description>
    </context-param>
    <context-param>
        <param-name>entityDelegatorName</param-name><param-value>default</param-value>
        <description>The Name of the Entity Delegator to use, defined in entityengine.xml</description>
    </context-param>
    <context-param>
        <param-name>mainDecoratorLocation</param-name>
        <param-value>component://practice/widget/CommonScreens.xml</param-value>
        <description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description>
    </context-param>
    <context-param>
        <param-name>widgetVerbose</param-name>
        <param-value>false</param-value>
        <description>Enable widget boundary comments. See org.ofbiz.widget.ModelWidget.widgetBoundaryCommentsEnabled().</description>
    </context-param>
    <context-param>
        <param-name>compressHTML</param-name>
        <param-value>false</param-value>
        <description>Remove unnecessary whitespace from HTML output.</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 mounting implementations 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 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><!-- 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>

 

     现在设置这个值: "component://practice/widget/CommonScreens.xml"  作为这个位置,你一会就会知道原因。这个位置是用来指出在 screens 中的主修饰器位置的。象如下:
     ${parameters.mainDecoratorLocation},通过改变它增加了代码的独立性,当我们需要改变主修饰器的位置。那时我们仅仅需要改为这个位置,将会应用到使用它的所有 screen。在 screen中这样做的好处是可以从其它组件中重用已存在的 screen,但是它用你的修饰器来修饰那个screen,仅仅是在相同模式用在所有地方和在所有组件中来显示mainDecoratorLocation.在这个应用开发的不远将来,当你在你的 screen 中增加修饰器的时候会集中到这点上。


 

7. 创建一个名为'control.xml'的文件。这个文件开始时小而简单,但随后我们增加功能而快速增长。

<?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"/> 
       <description>Practice Component Site Configuration File</description> 
       <owner>Copyright 2001-2009 The Apache Software Foundation</owner>  
		<errorpage>/error/error.jsp</errorpage>
<handler name="screen" type="view" class="org.ofbiz.widget.screen.ScreenWidgetViewHandler"/>       <!-- Request Mappings --> 
       <request-map uri="main"> 
           <security https="false" auth="false"/> 
           <response name="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> 	

8. 上移到上一级,创建一个新的目录,命名为'error'(hot-deploy/practice/webapp/practice/error)。

 

9. 在'error'目录中创建一个error.jsp文件,这个文件的内容可以取自任意存在的组件中。你显示错误信息页面的位置将被指定在controller.xml文件的开始位置,如上代码中的<errorpage>标签

 

10. 在组建目录practice中创建一个'widget'(hot-deploy/practice/widget),这个目录是用来处理用户界面的

 

11. 在widget中创建文件'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> 
</screens> 

12. 在命令行输入下面:java -Xmx256M -jar ofbiz.jar(可选,貌似现在项目比较小,也用不着多少内存)

然后访问:http://localhost:8080/practice/control/main

 

13. 在webapp目录"practice"创建一个index.jsp 文件 ( 文件的内容能拷贝自"example" 组件). 这个文件负责重定向响应至 control/main, 如果你给一个象如下的 URL http://localhost:8080/practice/ 。如果你给一个象如下的URL:http://localhost:8080/practice/unknown/request it  将会重定向到 web.xml  文件中指定的 redirectPath 。.既然那样, ContextFilter 将过滤出这个请求和使用这个重定向路径来重定向这个请求。

image

 

 

 

转载于:https://www.cnblogs.com/sysuys/archive/2012/07/12/2588783.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值