Versions Compared

Key

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

...

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

 

Code Block
themeConfluence
$ ./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.

...

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:

 

Code Block
$ ./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

...

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

     

    Code Block
    languagexml
    <?xmlversion="1.0"encoding="UTF-8"?>
    <screensxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            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.

...

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.

 

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.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:

 

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 "./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.

...

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:

 

Code Block
languagexml
titleOfbizDemoTypeData.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>
Code Block
languagexml
titleOfbizDemoDemoData.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


Code Block
languagexml
titleEntry 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 database tables, super easy, right!

 

...