Access to add and change pages is restricted. See: https://cwiki.apache.org/confluence/display/OFBIZ/Wiki+access

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 206 Next »

This tutorial is designed for beginners with little or no OFBiz experience. It covers the fundamentals of the OFBiz application development process. The goal is to make a developer conversant with best practices, coding conventions, basic control flow, and all other aspects which a developer needs for OFBiz customization.

This tutorial will help you in building your first "Demo Application" in OFBiz.

Important!

This tutorial is intended to be used with the branch 15.12 of Apache OFBiz.

For any questions or concerns, please use OFBiz User Mailing List. Details about the mailing lists are available here.

Source Code!

OFBiz
Download Apache OFBiz™
OFBiz Source Repository and Access

Tutorial
The source code of the Practice Application demonstrated in this tutorial can be downloaded from [TODO].

Framework Introduction Videos
OFBiz YouTube Channel or Vimeo can be accessed for the same.

Overview (Introduction to OFBiz)

Open For Business (OFBiz) is a suite of enterprise applications built on a common architecture using common data, logic and process components. The loosely coupled nature of the applications makes these components easy to understand, extend and customize.

The tools and architecture of OFBiz make it easy to efficiently develop and maintain enterprise applications. This makes it possible for us as the creators and maintainers of the project to quickly release new functionality and maintain existing functionality without extensive effort. It also makes it easy to customize and extend existing functionality when you have a specific need.

The architecture alone makes it easier for you to customize the applications to your needs, but many of the best flexibility points in the system would be meaningless and even impossible if the system was not distributed as open source software. OFBiz is licensed under the Apache License Version 2.0 which grants you the right to customize, extend, modify, repackage, resell, and many other potential uses of the system.

No restrictions are placed on these activities because we feel that they are necessary for effective use of this type of software. Unlike other open source licenses, such as the GPL, your changes do not have to be released as open source. There are obvious benefits to contributing certain improvements, fixes, and additions back to the core project, but some changes will involve proprietary or confidential information that must not be released to the public. For this reason, OFBiz uses the Apache License Version 2.0 which does not require this. For more information on open source licenses see the Open Source Initiative (OSI) website at www.opensource.org.

Another benefit of this open source model is that we receive constant feedback from those who are using the software. We have received countless bug fixes, improvement suggestions, and best-practice business advice from users and potential users of OFBiz. Many of the greatest features in the project were inspired by some comment or suggestion sent to the mailing lists associated with the project. With dozens of organizations using the software and probably hundreds of deployed sites using one piece or another of the project we generally get 20-30 emails each day about the project.

To make sure our functionality is timely and useful we always start by researching public standards and common usage for any component we are working on. This helps us support and use common vocabularies and gives us an instant breadth of options and features that can only be achieved through standards processes and other group efforts. It also opens doors in the future for flexible communication with other systems that are built around the same standards, both inside your organization and in partner or other organizations.

The applications and application components that come with the system provide you with a broad and flexible basis that can be used as-is with the best-practices based designs or customized to your own special needs. The applications facilitate management of everything from parties and products to accounting, customer service, and internal resource and asset management.

Reference: http://ofbiz.apache.org/apache-ofbiz-project-overview.html

Setting up and Running OFBiz

Download Apache OFBiz Framework

If you haven't already checkout Apache OFBiz Framework on your machine, let's do it. Anyone can checkout or browse the source code in the OFBiz public Subversion (SVN) repository. If you don't have Subversion, to install it you can go here for instructions.

To checkout the source code, simply use the following command (if you are using a GUI client, configure it appropriately):

For more details refer Apache OFBiz Source Repository page.

Running Apache OFBiz

  • Using the command line, build and start OFBiz (with demo data), use command:

 

$ ./ant load-demo start (For linux/mac it will work, for Windows $OFBIZ_HOME/ant.bat come bundled with OFBiz for Windows)

 

Above command will load demo data(Sample Data to run apps) comes with OFBiz in Derby Database, it comes configured with OFBiz.

  • Direct your browser to http://localhost:8080/webtools and login with username "admin" and password "ofbiz" and look around a bit. 
    That's it, Apache OFBiz is now running on your system!!

Create Your First Application (Hello World...)

Introduction to Components

An OFBiz component is a folder, containing a special xml file, named “ofbiz-component.xml”, that describes the resources to be loaded and required by the component.
OFBiz itself is a set of components.

  • framework components:These are lower level components that provides the technical layer and tools to the application components; the features provided by these components are typically the ones provided by any other development framework (data layer, business logic layer, transaction handling, data source pools, etc…)
  • application components:These are generic business components required for ERP applications that can be extended/customized (product, order, party, manufacturing, accounting etc…); application components have access to the services and tools provided by the framework components and to the services published by other application component.
  • special purpose components:These components are similar as applications components but meant for special purpose applications like ecommerce , google base integration , eBay integration etc.
  • hot-deploy components:This is an empty component available for custom development. Custom components can extend/override, the resources published by all the other components.

Create the component

It's very easy to setup a new custom component in OFBiz in hot-deploy directory. Using command line you just need run the following command and answer questions which are being asked for naming your custom component, component resource, webapp and base permission as shown below:

 

$ ./ant create-component
Buildfile: /home/ofbiz_dev/Apache_OFBiz/ofbiz-15.12/build.xml
create-component:
    [input] Component name: (e.g. mycomponent) [Mandatory]
ofbizdemo
    [input] Component resource name: (e.g. MyComponent) [Mandatory]
OfbizDemo
    [input] Webapp name: (e.g. mycomponent) [Mandatory]
ofbizdemo
    [input] Base permission: (e.g. MYCOMPONENT) [Mandatory]
OFBIZDEMO
     [echo] The following hot-deploy component will be created:
     [echo]               Name: ofbizdemo
     [echo]               Resource Name: OfbizDemo
     [echo]               Webapp Name: ofbizdemo
     [echo]               Base permission: OFBIZDEMO
     [echo]               Folder: /home/ofbiz_dev/Apache_OFBiz/ofbiz-15.12/hot-deploy/ofbizdemo
     [echo]        
    [input] Confirm:  (Y, [N], y, n)
y

 

Component Directory Structure In IDE 

Running your first application

Before running our first component, let's say 'Hello to the World'

  1. Simply open $OFBIZ_HOME/hot-deploy/ofbizdemo/widget/OfbizDemoScreens.xml file from ofbizdemo component(you just created)

     

    <?xmlversion="1.0"encoding="UTF-8"?>
            xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/widget-screen.xsd">
        <screenname="main">
            <section>
                <actions>
                    <setfield="headerItem"value="main"/><!-- this highlights the selected menu-item with name "main" -->
                </actions>
                <widgets>
                    <decorator-screenname="OfbizDemoCommonDecorator"location="${parameters.mainDecoratorLocation}">
                        <decorator-sectionname="body">
                            <labeltext="Hello World!! :)"/>
                        </decorator-section>
                    </decorator-screen>
                </widgets>
            </section>
        </screen>
    </screens>

     

    We have only added the <label text="Hello World!! :)" />

  2. Now you will need to restart OFBiz by reloading data($ ./ant load-demo start). It's required as you have created a new component with some security data for you component (Setup by default in your component data directory as OfbizDemoSecurityGroupDemoData.xml) and as you will restart it, ofbizdemo component will also be loaded.
  3. As OFBiz restarted direct your browser to your application here http://localhost:8080/ofbizdemo
  4. You will be asked to login. Login with user: admin password: ofbiz.
  5. As you login you will see ofbizdemo application up with the hello world message you have put in screen as shown in below given image.
    That's it, congratulations your first component is setup and running.

Creating First Database Entity (Table) 

Defining entity

To create custom Entities/Tables in database, you simply need to provide entity definition in  $OFBIZ_HOME/hot-deploy/ofbizdemo/entitydef/entitymodel.xml file of your ofbizdemo application. This file structure is already setup when you used ant target to setup your component. You simply need to go in and provide entity definition as shown below. Here we are going to add two new entities for ofbizdemo application.

 

<?xml version="1.0" encoding="UTF-8"?>
 
    xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/entitymodel.xsd">
 
    <title>Entity of an Open For Business Project Component</title>
    <description>None</description>
    <version>1.0</version>
 
    <entity entity-name="OfbizDemoType" package-name="org.ofbiz.ofbizdemo" title="OfbizDemo Type Entity">
        <field name="ofbizDemoTypeId" type="id-ne"><description>primary sequenced ID</description></field>
        <field name="description" type="description"></field>
        <prim-key field="ofbizDemoTypeId"/>
    </entity>
 
    <entity entity-name="OfbizDemo" package-name="org.ofbiz.ofbizdemo" title="OfbizDemo Entity">
        <field name="ofbizDemoId" type="id-ne"><description>primary sequenced ID</description></field>
        <field name="ofbizDemoTypeId" type="id-ne"></field>
        <field name="firstName" type="name"></field>
        <field name="lastName" type="name"></field>
        <field name="comments" type="comment"></field>
        <prim-key field="ofbizDemoId"/>
        <relation type="one" fk-name="ODEM_OD_TYPE_ID" rel-entity-name="OfbizDemoType">
            <key-map field-name="ofbizDemoTypeId"/>
        </relation>
    </entity>
 
</entitymodel>

 

Now have a look at $OFBIZ_HOME/hot-deploy/ofbizdemo/ofbiz-component.xml file. You already have resource entry made in it for loading these entities from their definitions to database when component loads. As shown below:

 

<entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/>

 

To check simply re-start OFBiz (Ctrl+C followed by "./ant start") and direct your browser to Entity Data Maintenance Tool here: https://localhost:8443/webtools/control/entitymaint and search for entities OfbizDemoType and OfbizDemo. You will see it as shown in below given image.

Entity List View from Webtools

Preparing data for entity

As you have setup your custom entities, now is the time to prepare some sample xmldata for it. You can do it in data xmlfiles already setup under data directory of your component as  $OFBIZ_HOME/hot-deploy/ofbizdemo/data/OfbizDemoTypeData.xml and  $OFBIZ_HOME/hot-deploy/ofbizdemo/data/OfbizDemoDemoData.xml. Set it up as shown below:

OfbizDemoTypeData.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<entity-engine-xml>
    <OfbizDemoType ofbizDemoTypeId="INTERNAL" description="Internal Demo - Office"/>
    <OfbizDemoType ofbizDemoTypeId="EXTERNAL" description="External Demo - On Site"/>
</entity-engine-xml>

 

OfbizDemoDemoData.xml

 

 <?xml version="1.0" encoding="UTF-8"?>
<entity-engine-xml>
    <OfbizDemo ofbizDemoId="SAMPLE_DEMO_1" ofbizDemoTypeId="INTERNAL" firstName="Sample First 1" lastName="Sample Last 1" comments="This is test comment for first record."/>
    <OfbizDemo ofbizDemoId="SAMPLE_DEMO_2" ofbizDemoTypeId="INTERNAL" firstName="Sample First 2" lastName="Sample last 2" comments="This is test comment for second record."/>
    <OfbizDemo ofbizDemoId="SAMPLE_DEMO_3" ofbizDemoTypeId="EXTERNAL" firstName="Sample First 3" lastName="Sample last 3" comments="This is test comment for third record."/>
    <OfbizDemo ofbizDemoId="SAMPLE_DEMO_4" ofbizDemoTypeId="EXTERNAL" firstName="Sample First 4" lastName="Sample last 4" comments="This is test comment for fourth record."/>
</entity-engine-xml>

 

Now again have a look at $OFBIZ_HOME/hot-deploy/ofbizdemo/ofbiz-component.xml file. You already have resource entry made in it for loading data prepared in these files as:

Entry to be done in ofbiz-component.xml

 

<entity-resource type="data" reader-name="seed" loader="main" location="data/OfbizDemoTypeData.xml"/>
<entity-resource type="data" reader-name="demo" loader="main" location="data/OfbizDemoDemoData.xml"/>

Loading data in entity

At this moment to load this sample data into entities/tables defined you can either run "ant load-demo" on console or can directly go here in webtools to load entity xml https://localhost:8443/webtools/control/EntityImport.

Simply put your xml data in " Complete XML document (root tag: entity-engine-xml):" text area and hit "Import Text", as shown in below given image

XML Data Import from Webtools

As you will hit Import Text, it will load data and will show the result as shown below:

XML Data Load Result

After completing the data load process again visit Entity Data Maintenance(https://localhost:8443/webtools/control/entitymaint) and check your entities, you will find this data here that you just loaded.


That's it, you have successfully imported the data in the entities, super easy, right!

 



Whats next?

If you have followed all the steps and developed practice application from this tutorial then this will help you in understanding other implementation in OFBiz. These things are basic foundation of working in OFBiz. Now you know, how you can start development in OFBiz. Don't leave behind the extra links provided in this tutorial as they will help you a lot in understanding the things which are given there in detail.
Here is another good reading can be of help is available at FAQ Tips Tricks Cookbook HowTo
Now the next thing comes in the way is the business processes which are really needed to be understood well for understanding OOTB process flow in OFBiz and OOTB data model, so for this, books are available at : OFBiz Related Books. Understanding well the OFBiz OOTB available data model and business processes will help in building better business solutions top of it.

Now you are ready to dive in. Welcome to OFBiz world.

  • No labels