`

ofbiz入门教程(2)

阅读更多
Part 1
Create a Component
Create the sub-directory (folder) in hot-deploy/ and name it "practice"(hot-deploy/practice). The directory name should match the new components name that we are creating.
Note : Remember that all customized development is done at this place only.
Create the ofbiz-component.xml file on path hot-deploy/practice and place the following content in it (for reference you can check this file in any other component of OFBiz):
<?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"
       base-permission="OFBTOOLS"
       location="webapp/practice"
       mount-point="/practice"
       app-bar-display="false"/>
</ofbiz-component>
Explanation of ofbiz-component.xml
The ofbiz-component.xml file is responsible for letting OFBiz know where resources are at as well as allowing you to add to the classpath.
The 'resource-loader name' can be any string. Here we are setting it as "main". The 'type' tells OFBiz that we will be loading a component.
<resource-loader name="main" type="component"/>
In <webapp> tag, we have different attributes and their purpose is as follows:
<webapp name="practice"
       title="Practice"
       server="default-server"
       base-permission="OFBTOOLS"
       location="webapp/practice"
       mount-point="/practice"
       app-bar-display="false"/>
name :- defines the name of our web application.
title :- This will be the title of the application which will be shown in the top navigation.
server :- This will let OFBiz know what server to use.
base-permission :- This line requires that the user should have the OFBTOOLS permission to be able to use the application. Since the 'admin' user has this permission we do not have to create any new users.
location :- This will be the location that is the default base directory for the server.
mount-point :- This is the URL used to access this resource. in this case it would be localhost:8080/practice.
app-bar-display :- This will let OFBiz know if we want our component to show up in the main application tabs that are part of the common ofbiz decorator.
Creating the web app
Create a "webapp" directory in the practice component (hot-deploy/practice/webapp).
This directory contains all the webapp related files for the component we are creating.
Create a sub-directory inside the webapp directory by the name of  "practice" which is the name of the webapp which you are going to develop (hot-deploy/practice/webapp/practice). A component can have multiple webapps attached to it. e.g. In the "marketing" component there are two webapps "marketing" and "sfa".
The webapp we are creating will follow the J2EE webapp standards.
Create WEB-INF directory in your webapp (hot-deploy/practice/webapp/practice/WEB-INF).
An OFBiz web application requires two configuration files, a controller.xml and a web.xml. The controller.xml tells OFBiz what to do with various requests from visitors: what actions to take and what  pages to render. web.xml tells OFBiz what resources (database and business logic access) are available for this web application and how to handle web-related issues, such as welcome pages, redirects, and error pages.
Create a file named "web.xml"(web.xml follows j2ee webapp specs). Contents of this file can be copied from any of the existing component e.g. /framework/example component. The Important values to change are the <display-name>, the localDispatcherName, the mainDecoratorLocation and the webSiteId.
<context-param>
    <param-name>webSiteId</param-name>
    <param-value>PRACTICE</param-value>
    <description>A unique ID used to look up the WebSite entity to get information about catalogs, etc.</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>mainDecoratorLocation</param-name>
     <param-value>component://practice/widget/PracticeScreens.xml</param-value>
     <!-- change the path to the following if the above doesn't work for you -->
     <!-- <param-value>component://practice/webapp/practice/widget/PracticeScreens.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>
For now just put websiteId as "PRACTICE", you will explanation after some time in this tutorial only.
For now put the value: "component://practice/widget/CommonScreens.xml" in for the mainDecoratorLocation and you will see why in a while. This location is used in pointing to the main decorator location in screens like
${parameters.mainDecoratorLocation}
Which increases the code Independence from changing the path at many places when we need to change the main decorator location. At that time we just need to change the location there only and it will work for all the screens where it has been used. One more advantage of doing this in screens is the purpose of resuability of existing screens which we can use from other components, but it decorate that screen by your decorator only as the same pattern is used at all the places and in all the components to show the mainDecoratorLocation. Concentrate on this when you add decorators in your screens in not too distant future with the development of this application.
Create a file named "controller.xml" (used by ofbiz webapp controller)  This file will be small and simple at first but will grow as we add functionality later on. For now insert the following code:
<?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>
       <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"/>
       <!-- change the path to the following if the above doesn't work for you -->
       <!-- <view-map name="main" type="screen" page="component://practice/webapp/practice/widget/PracticeScreens.xml#main"/> -->

       <!-- end of view mappings -->
</site-conf>
Move up one level and create a new directory named 'error'(hot-deploy/practice/webapp/practice/error).
Create a file error.jsp inside the "error" directory. Contents of this file can be copied from any of the existing component e.g. example component.
The location of your error page will be specified in the beginning of your controller.xml file like <errorpage>/error/error.jsp</errorpage> . You will need to make or copy over a /webapp/practice/error/error.jsp page to show an error message to the user.
Create a sub-directory inside your component directory "practice" named "widget"(hot-deploy/practice/widget). This directory will contain your forms, menus, and screens which will be created for UI.
Create a file inside the directory "widget" named "PracticeScreens.xml". Contents of this file can be copied from any existing component  e.g. example component.
As now onwards you will be able to create screens views so an important reading at this place will be Best Practices Guide.
<?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>
Now that we have the basic elements in place let's review the basic flow no matter how large or complex your component gets. First, a request will be made by a browser to see a specific resource. Take for example the request: "localhost:8080/practice/control/main"
When OFBiz sees this request it will look at the /practice section first. This is because in our ofbiz-component.xml file we said our webapps mount point would be /practice. Now OFBiz knows that our practice component will handle the rest of the request.
OFBiz will then look at our controller.xml file. Inside our controller.xml file we have request-maps and view-maps. If it finds a request-map with the name 'main' it will use the associated view-map, as follows. The request-map can either specify a view, or as we will see later an event or a service. If it specifies a view it will look further down in the controller.xml file and see if there is a view-map with the name specified by the value tag in the request-map.
For now we will keep it simple and assume that all the views go to a type=screen. If this is the case then the page tag will specify a path to a screen definition file as well as a screen name to display after the "#" sign.
Now its the time to run you first practice application!
Start the server by typing the following at the command line : java -Xmx256M -jar ofbiz.jar (the -Xmx256M command just ensures that the program has enough memory) Then, hit the url http://localhost:8080/practice/control/main in your browser.  Your browser should show "This is first practice" as seen below.
Output Screen :

Create a file in the webapp directory "practice" named index.jsp (Contents of this file can be copied from the "example" component). This file is responsible for redirecting the response to control/main if you give a url such as  http://localhost:8080/practice/. If you give a url such as http://localhost:8080/practice/unknown/requestit will be redirected to the redirectPath specified in web.xml. In that case, ContextFilter will filter out the request and use the redirect path to redirect the request.
分享到:
评论

相关推荐

    Ofbiz 入门教程

    ### Ofbiz 入门教程详解 #### 一、Ofbiz 概述与环境搭建 **1. Ofbiz 简介** Ofbiz 是一个开源的企业级应用框架,它提供了全面的功能来支持电子商务业务流程,包括销售、库存管理、订单处理等。作为 Apache 软件...

    原创 Ofbiz 入门教程

    ### Ofbiz 入门教程详解 #### 一、Ofbiz 概述 Ofbiz(Open for Business)是一款开源的企业级商务应用系统,它利用了一系列优秀的开源项目如Tomcat、Ant、BeanShell、Jboss等,构建出了一个强大的系统平台。Ofbiz...

    ofbiz入门教程-初学者开发指南

    要开始使用 Ofbiz,首先需要安装 J2SDK 1.4。从 Java 官方网站下载并设置好JAVA_HOME环境变量。然后,从 Ofbiz 官方网站下载 Complete 包,解压后置于任意目录,例如 "C:\ofbiz"。在这个目录下,你会发现 catalina ...

    OFBiz经典入门教程加速度编写

    《OFBiz经典入门教程加速度编写》是一篇针对开源企业应用框架OFBiz的入门教程,旨在帮助初学者快速掌握OFBiz的基本使用和开发技巧。OFBiz(Open For Business Project)是一个全面的企业级业务应用程序框架,它由...

    ofbiz开发者入门教程

    在本教程中,我们将深入探讨如何入门Apache Ofbiz的开发,这是一个开源的企业级应用框架,专为电子商务、供应链管理和企业资源规划等业务流程设计。Ofbiz提供了强大的组件化架构,使得开发者可以方便地构建和扩展...

    ofbiz入门实例(jiasudu制作)

    【标题】"Ofbiz入门实例(jiasudu制作)"是一个针对开源企业应用系统Ofbiz的实践教程,由博主jiasudu精心制作。这个实例教程旨在帮助初学者快速理解并上手Ofbiz,从而能够构建和管理自己的企业级应用程序。 【描述】...

    ofbiz 入门+增删改查+实体

    Apache OFBiz是一个开源...总之,OFBiz入门涉及环境配置、组件和应用的创建、实体模型定义以及CRUD操作的实现。通过这些步骤,你可以开始开发基于OFBiz的业务应用程序,利用其强大的功能和灵活性来满足企业的各种需求。

    OFBIZ快速入门OFBIZ快速入门

    【OFBIZ快速入门】 OFBiz,全称Open For Business Project,是一个开源的企业级应用框架,专注于电子商务和业务流程管理。OFBiz旨在提供一个全面、可扩展且灵活的解决方案,适用于各种规模的企业。本篇文章将带你...

    ofbiz开发入门总结

    Ofbiz社区提供了大量的文档和教程,包括官方的用户指南、开发者手册以及在线论坛,这些都是学习Ofbiz的宝贵资源。同时,阅读和理解Ofbiz的源码,能够帮助你更深入地理解其工作原理。 总结来说,Ofbiz是一个功能强大...

    Ofbiz快速开发入门详解

    总的来说,《Ofbiz快速开发入门详解》是一本实用的教程,适合对Java Web开发感兴趣,希望掌握企业级应用框架的开发者。通过这本书,你不仅能理解Ofbiz的基本架构,还能学会如何利用Ofbiz快速开发出满足业务需求的...

    OFBiz入门实训教程

    NULL 博文链接:https://jiasudu.iteye.com/blog/2091874

    OFBiz教程_-_初学者的开发指南

    本教程旨在为初次接触OFBiz框架的开发者提供一个全面且易于理解的入门指南。OFBiz是一个开源的企业级电子商务框架,提供了完整的业务流程管理解决方案,包括订单处理、库存管理、客户服务支持等功能。通过本教程的...

    ofbiz开发教程

    **OFBiz开发教程** OFBiz,全称Open For Business Project,是一个开源的企业级应用套件,主要用于构建电子商务、供应链管理、客户关系管理等业务系统。本教程专为初学者设计,旨在帮助您快速掌握OFBiz的基本操作和...

    OFBIZ10.04组件开发入门.doc

    **OFBIZ 10.04 组件开发入门** OFBIZ,全称为Open For Business Project,是一个基于Java的企业级应用框架,主要用于构建电子商务、供应链管理、CRM等复杂业务系统。本文档主要针对OFBIZ 10.04版本,通过讲解Region...

    OFBiz开发快速入门

    "OFBiz开发快速入门.pdf"很可能是详细的教程文档,它可能涵盖OFBiz的安装步骤、基本操作、API使用示例以及最佳实践。"OFBiz其它资源.txt"可能包含进一步的学习资源链接、社区论坛地址或常见问题解答。至于"hello...

    ofbiz资料大全

    OFBiz开发快速入门.rar OFBiz-技术文档.rar OFBiz API中文版.rar Apache OFBiz Cookbook Sep 2010.rar Opentaps widget使用说明.rar OFBiz.Development.2008.rar Groovy中文教程.rar freemarker中文手册.rar ...

    OFBiz教程-初学者开发指南

    本教程专为初学者设计,旨在解决OFBiz入门过程中的常见问题,帮助开发者快速理解并掌握OFBiz的基本操作和开发流程。 **1. 创建组件定义文件** 在OFBiz中,每个组件都是一个独立的功能模块。首先,你需要在`hot-...

Global site tag (gtag.js) - Google Analytics