Versions Compared

Key

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

...

For OFBiz existing components - additional plugins components, check them out using the Gradle tasks or the GIT command

1.Checkout  Checkout via Gradle tasks

To get all components use pullAllPluginsSource(This command should be run from ofbiz-framework home). Beware this deletes a previously existing plugins directory.

Code Block
For Linux/Mac: $ ./gradlew pullAllPluginsSource
For Windows: > gradlew pullAllPluginsSource

2. Checkout via via GIT command(Following commands should be run from ofbiz-framework home)

For more details refer please refer: Apache OFBiz Source Repository page.

Running Apache OFBiz

...

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

Code Block
themeConfluence
For Linux/Mac: $ ./gradlew cleanAll loadAll ofbiz
For Windows: > gradlew cleanAll loadAll ofbiz

The above command will load demo data, (Sample Data to run apps) which comes with OFBiz, in Derby Database Database. Apache Derby comes configured as a default database with OFBiz ready to use.

For more options see README.MD.

...

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

Reference Tutorial
Create a Plugin in OFBiz

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.

...

  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"
             xmlns="http://ofbiz.apache.org/Widget-Screen" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Screen 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, the 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 the ofbizdemo application up with the hello world "Hello World" message you have put on screen as shown below the given image.
    That's it, congratulations your first component is set up and running.

...

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 file of your ofbizdemo application.  This 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 the ofbizdemo application.

If we talk about SQL then you should create tables(entities) using "create table" statement similarly in OFBiz you should create tables using XML as shown below.

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

...

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


If we talk about SQL then you should insert data into tables(entities) using "insert into" statement similarly in OFBiz you can do the same work using XML, shown above.

Loading data in the entity

...

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!

Form and Services

In our previous section, we have seen how to create the entities (tables), now it's time to create a form that will allow you to make entries in that entity.

...

Now again have a look at the $OFBIZ_HOME/plugins/ofbizDemo/ofbiz-component.xml file. You already have resource entry made in it for loading services defined in this file as:

Code Block
languagexml
<!-- service resources: model(s), eca(s) and group definitions -->
<service-resource type="model" loader="main" location="servicedef/services.xml"/>

...

Code Block
languagexml
titleOfbizDemoForms.xml
<?xml version="1.0" encoding="UTF-8"?>
<forms xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://ofbiz.apache.org/Widget-Form" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Form http://ofbiz.apache.org/dtds/widget-form.xsd">
 
    <form name="AddOfbizDemo" type="single" target="createOfbizDemo">
        <!-- We have this utility in OFBiz to render form based on service definition. 
             Service attributes will automatically lookedup and will be shown on form
        -->
        <auto-fields-service service-name="createOfbizDemo"/>
        <field name="ofbizDemoTypeId" title="${uiLabelMap.CommonType}">
            <drop-down allow-empty="false" current-description="">
                <!---We have made this drop down options dynamic(Values from db) using this -->
                <entity-options description="${description}" key-field-name="ofbizDemoTypeId" entity-name="OfbizDemoType">
                    <entity-order-by field-name="description"/>
                </entity-options>
            </drop-down>
        </field>
        <field name="submitButton" title="${uiLabelMap.CommonAdd}"><submit button-type="button"/></field>
    </form>
</forms>

Here you can notice that we have used auto-fields-service to auto-generate the form based on service definition IN/OUT attributes. 

...

Before you go to the form and start creating OfbizDemo records from add form, you will need to make an entry in the $OFBIZ_HOME/plugins/ofbizDemo/webapp/ofbizDemo/WEB-INF/controller.xml file for the target service which will be called when a form is submitted. You can do it as shown below under Request Mappings in your ofbizdemo apps controller file:

Code Block
languagexml
<request-map uri="createOfbizDemo">
    <security https="true" auth="true"/>
    <event type="service" invoke="createOfbizDemo"/>
    <response name="success" type="view" value="main"/>
</request-map>

...

Let's create a find form for the entity OfbizDemo so that you search OfbizDemos being created.

1.) Add the forms (FindOfbizDemo and ListOfbizDemo) in OfbizDemoForms.xml

...

Form or Screen's action tag is used for data preparation logic for your view.

Info

We have used OOTB OFBiz generic service performFind to do the search operations which is easy and efficient to use when you have to perform a search on one entity or one view entity.

...


4.) Now, let's add a new menu for showing find option.
Creating a menu is really simple in OFBiz, all the menus are defined is *menus.xml.
When we create a component from a GraGradle task, we get a file named named OfbizDemoMenus.xml

Make the following entry in the OfbizDemoMenus.xml file.

...

The service "createOfbizDemo" that you created earlier was using engine="entity-auto"(see services.xml file) and hence you didn't need to provide its implementation and OFBiz took care of create operation.  When you need to work on complex operations in service involving multiple entities from database and custom logics to be built, you need to provide custom implementation to your service. In this section, we will focus on this.

...

Code Block
languagexml
titleservices.xml
 <service <service name="createOfbizDemoByJavaService" default-entity-name="OfbizDemo" engine="java"
        location="com.companyname.ofbizdemo.services.OfbizDemoServices" invoke="createOfbizDemo" auth="true">
    <description>Create an Ofbiz Demo record using a service in Java</description>
    <auto-attributes include="pk" mode="OUT" optional="false"/>
    <auto-attributes include="nonpk" mode="IN" optional="false"/>
    <override name="comments" optional="true"/>
</service>


Info

Notice this time we have this time used engine="java".


2.) Create package "com.companyname.ofbizdemo.services" in your ofbizDemo components src/main/java directory (create those if they don't exist in your src directory). 

...