...
Info | ||
---|---|---|
| ||
OFBiz Tutorial Framework Introduction Videos |
Table of Contents |
---|
Overview (Introduction to OFBiz)
Open For Business Apache OFBiz (OFBiz hereafter) is a suite of enterprise applications built on a common architecture using a Unified Data Model, common data, logic , and process components. The loosely coupled nature of the applications makes these components easy to understand, extend and customize.
...
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 GIT repository. If you don't have Git, to install it you can go here for instructions.
To clone the source code, simply use the following command (if you are using a GUI client, configure it appropriately):
- Download ofbiz-framework branch release18.12codebase: $ git clone https://gitbox.apache.org/repos/asf/ofbiz-framework.git ofbiz-framework
- git branch Now point ofbiz-framework codebase to release18.12: $ git checkout origin/release18.12
...
To get all components use pullAllPluginsSource(This command should be run from ofbiz-framework home). Beware this deletes a previously existing plugins directory.
...
2.Checkout via GIT command(Following commands should be run from ofbiz-framework home)
- Download ofbiz-plugins branch release18.12codebase: $ git clone https://gitbox.apache.org/repos/asf/ofbiz-plugins.git plugins
- git branch Now point ofbiz-plugins codebase to release18.12: $ git checkout origin/release18.12
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:
...
- 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
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 |
Running your first application
Before running our first component, let's say 'Hello to the World'
Reference document:
Understanding the OFBiz Widget Toolkit
Simply open $OFBIZ_HOME/plugins/ofbizDemo/widget/OfbizDemoScreens.xml file from the ofbizDemo plugin (you just created)
Code Block language xml <?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!! :)" />
- 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.
- As OFBiz restarted direct your browser to your application here https://localhost:8443/ofbizDemo
- You will be asked to log in. Login with user: admin password: ofbiz.
- As you log in you will see the 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 set up and running.
Creating First Database Entity (Table)
Reference document:
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 the ofbizdemo application.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<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 the entity
At this moment to load this sample data into entities/tables defined you can either run "./gradlew loadAll" on the console or can directly go here in webtools to load entity XML https://localhost:8443/webtools/control/EntityImport.
...
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.
Create a Service
Reference Document:
Before preparing the form, let's write a service to create records in the database for the OfbizDemo entity in the service definition XML file ($OFBIZ_HOME/plugins/ofbizDemo/servicedef/services.xml)
...
Info |
---|
Running service via Web Tools: This is a smart utility provided by the framework to run your service. On submission of the form above, you will present a form to enter IN parameters of the service. |
Use of UI Labels (Introduction)
Reference Document:
How to localize Product and Categories descriptions
Internationalization of Apache OFBiz is really easy, we define the UI Labels in various languages, and on the basis of the user's locale, the respective label is shown.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-properties.xsd"> <property key="OfbizDemoApplication"> <value xml:lang="en">OfbizDemo Application</value> <value xml:lang="zh">OfbizDemo应用程�?</value> <value xml:lang="zh-TW">OfbizDemo應用程�?</value> </property> <property key="OfbizDemoCompanyName"> <value xml:lang="en">OFBiz: OfbizDemo</value> <value xml:lang="zh-TW">OFBiz: OfbizDemo</value> </property> <property key="OfbizDemoCompanySubtitle"> <value xml:lang="en">Part of the Apache OFBiz Family of Open Source Software</value> <value xml:lang="it">Un modulo della famiglia di software open source Apache OFBiz</value> <value xml:lang="zh">开�?软件OFBiz的组�?部分</value> <value xml:lang="zh-TW">開�?軟體OFBiz的組�?部分</value> </property> <property key="OfbizDemoViewPermissionError"> <value xml:lang="en">You are not allowed to view this page.</value> <value xml:lang="zh">�?�?许你�?览这个页�?�。</value> <value xml:lang="zh-TW">�?�?許您檢視這個�?�?�.</value> </property> </resource> |
Create the add Form
Let's create our first form for this service and for that let's edit the existing file at location $OFBIZ_HOME/plugins/ofbizDemo/widget/OfbizDemoForms.xml and add Create Form for OfbizDemo as shown below:
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="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="main-decorator" location="${parameters.mainDecoratorLocation}"> <decorator-section name="body"> <screenlet title="Add Ofbiz Demo"> <include-form name="AddOfbizDemo" location="component://ofbizDemo/widget/OfbizDemoForms.xml"/> </screenlet> </decorator-section> </decorator-screen> </widgets> </section> </screen> </screens> |
Controller Entry for Form
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:
...
The primary key(ofbizDemoId) is not needed to be sent in with the form, it will be auto sequenced by OFBiz in database records.
Create a Find Form
Let's create a find form for the entity OfbizDemo so that you search OfbizDemos being created.
...
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8"?> <menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Widget-Menu" xsi:schemaLocation="http://ofbiz.apache.org/Widget-Menu http://ofbiz.apache.org/dtds/widget-menu.xsd"> <menu name="MainAppBar" title="${uiLabelMap.OfbizDemoApplication}" extends="CommonAppBarMenu" extends-resource="component://common/widget/CommonMenus.xml"> <menu-item name="main" title="${uiLabelMap.CommonMain}"><link target="main"/></menu-item> <menu-item name="findOfbizDemo" title="${uiLabelMap.OfbizDemoFind}"><link target="FindOfbizDemo"/></menu-item> </menu> </menus> |
Use of UI Labels (Completion)
As we have seen above Internationalization of Apache OFBiz is really easy, we define the UI Labels in various languages, and on the basis of the user's locale, the respective label is shown.
...
Now simply restart the server, under the ofbizdemo application (https://localhost:8443/ofbizDemo/control/main) you will see the Find menu option.
Services using other engines
Whenever you have to build a business logic you should prefer to write services to leverage features from its built-in Service Engine.
The service "createOfbizDemo" that you created earlier was using engine="entity-auto" 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.
Service in Java
You can implement a service in Java as directed here in the below-given steps:
...
|
Service in Groovy
To utilize features of on-the-fly compilation and fewer lines of code you can implement services for building business logic in OFBiz using Groovy DSL.
...
To get more details about using Groovy DSL for service and events implementation in Apache OFBiz you can refer document created by Jacopo Cappellato in OFBiz Wiki here.
Events
Events demonstration
Events in Apache OFBiz are simply methods used to work with HttpServletRequest and HttpServletResponse objects. You don't need to provide definitions of these as you did with services. These are directly called from the controller. Events are also useful when you want to add custom server-side validations to input parameters. For performing database operations you still call prebuilt services from events.
...
4.) Now to test the event you can simply change the AddOfbizDemo form target to read "createOfbizDemoEvent" and as it's submitted now it will call your event.
Difference between service and event
Here are some differences between services and events,
...
Criteria | Services | Events |
---|---|---|
Require Definition | Yes | No |
Implementation possibilities | Entity auto, Java, Simple (XML) & Groovy | Simple (XML), Java & Groovy |
Return Type | Map | String |
Used to write business logic | Yes | No |
Job Scheduling possible | Yes | No |
Customizing User Interface
Using FreeMarker Template and Groovy Script
Okay, so we are here in the last part of the OFBiz tutorial. In this part, we will focus on customizing the UI layer of Apache OFBiz for business management apps i.e. backend apps and esp. Most of the time you will find the OFBiz Widgets are enough. But sometimes the important thing is to develop applications as users exactly want them.
...
6.) Run your ofbiz demo application and go to the new tab you just added. You should have viewed as:
Creating Custom Decorator
Having your UI in Freemarker gives you the freedom to experiment with it, doing CSS tweaks, and make your application the way a user wants. In this section, we will see how we can do that.
...
You may want to add your own CSS or JS files, you can include those the same way we did for Bootstrap files.
What's next?
If you have followed all the steps and developed practice applications from this tutorial then this will help you in understanding other implementations in OFBiz. These things are the 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 that can be of help is available at FAQ Tips Tricks Cookbook HowTo.
Now the next thing that comes in the way is the business processes which are really needed to be understood well for understanding the 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.
...