Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Direct your browser to https://localhost:8443/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 provide 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 components.
  • plugins components: These components are similar to applications components but meant for special purpose applications like eCommerce , google base integration, eBay integration, etc

Create the plugin/component

It's very easy to set up a new custom component in OFBiz in the plugins directory. Using the command line you just need to run the following command.


Code Block
$ ./gradlew createPlugin -PpluginId=ofbizDemo


Image Added

Running your first application

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

  1. Simply open $OFBIZ_HOME/plugins/ofbizDemo/widget/OfbizDemoScreens.xml file from the ofbizDemo plugin (you just created)


    Code Block
    languagexml
    <?xmlversion="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>
                <actions>
                    <set field="headerItem" value="main"/><!-- this highlights the selected menu-item with name "main" -->
                </actions>
                <widgets>
                    <decorator-screen name="OfbizDemoCommonDecorator" location="${parameters.mainDecoratorLocation}">
                        <decorator-section name="body">
                            <label text="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($ ./gradlew loadAll ofbiz). It's required as you have created a new component with some security data for your 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 https://localhost:8443/ofbizDemo
  4. You will be asked to log in. Login with user: admin password: ofbiz.
  5. As you log in you will see ofbizdemo application up with the hello world message you have put on screen as shown below the 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 the database, you simply need to provide entity definition in the $OFBIZ_HOME/plugins/ofbizDemo/entitydef/entitymodel.xml file of your ofbizdemo application. This file structure is already set up when you used the Gradle task to set up 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.


Code Block
languagexml
<?xml version="1.0" encoding="UTF-8"?>
 
<entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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.apache.ofbiz.ofbizdemo" title="OfbizDemo Type Entity">
        <field name="ofbizDemoTypeId" type="id"><description>primary sequenced ID</description></field>
        <field name="description" type="description"></field>
        <prim-key field="ofbizDemoTypeId"/>
    </entity>
 
    <entity entity-name="OfbizDemo" package-name="org.apache.ofbiz.ofbizdemo" title="OfbizDemo Entity">
        <field name="ofbizDemoId" type="id"><description>primary sequenced ID</description></field>
        <field name="ofbizDemoTypeId" type="id"></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 the $OFBIZ_HOME/plugins/ofbizDemo/ofbiz-component.xml file. You already have resource entries made in it for loading these entities from their definitions to the database when the component loads. As shown below:


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

To check simply re-start OFBiz (Ctrl+C followed by "./gradlew ofbiz") 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.

Image Added