Versions Compared

Key

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

...

  1. For any additional queries and concerns you can refer Example component. You will always find the code in example component to be the latest code of OFBiz. Take reference whenever you want to see some sample code for the development of this application, this will help you in future developments as well.
    Every new feature is first added in the Example component for the references.
  2. Before starting the development of this application you must read the contents from:
    OFBiz Contributors Best PracticesCoding Conventions and Best Practices Guide
  3. Don't copy any file from other component, as the revision number for the file is also copied. Always create a new file and, if required, then copy the contents of the file." Also be conscious about the unused code as well.
  4. For searching any of the document the best place is at : OFBiz Documentation Index.
  5. Right from the beginning, reading the console log must be a habit to make troubleshooting easy and understanding the system well.
  6. You can find the source code of this application attached with this document that you are going to develop but it is preferred to just take reference from it. It can be downloaded from here: Download Source (wink)

Part 1

Create a Component

...

  1. Create the sub-directory (folder) in hot-deploy/ and name it "practice"(hot-deploy/practice). The directory name should match the new components name that we are creating.
    Note : Remember that all customized development is done at this place only. 

...

  1. Create the ofbiz-component.xml file on path hot-deploy/practice and place the following content in it (for reference you can check this file in any other component of OFBiz):
    Code Block
    
    <?xml version="1.0" encoding="UTF-8"?>
    <ofbiz-component name="practice"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/ofbiz-component.xsd">
          <resource-loader 	name="main" type="component"/>
        <webapp name="practice"
           title="Practice"
           server="default-server"
           base-permission="OFBTOOLS"
           location="webapp/practice"
           mount-point="/practice"
           app-bar-display="false"/>
    </ofbiz-component>
    

Explanation of ofbiz-component.xml

...

...

  1. The ofbiz-component.xml file is responsible for letting OFBiz know where resources are at as well as allowing you to add to the classpath.

...

  1. # The 'resource-loader name' can be any string. Here we are setting it as "main". The 'type' tells OFBiz that we will be loading a component.
    Code Block
    
    <resource-loader name="main" type="component"/>
    
    3. In <webapp> tag, we have different attributes and their purpose is as follows:
    Code Block
    
    <webapp name="practice"
           title="Practice"
           server="default-server"
           base-permission="OFBTOOLS"
           location="webapp/practice"
           mount-point="/practice"
           app-bar-display="false"/>
    

...

    1. name :- defines the name of our web application.

...

    1. title :- This will be the title of the application which will be shown in the top navigation.

...

    1. server :- This will let OFBiz know what server to use.

...

    1. base-permission :- This line requires that the user should have the OFBTOOLS permission to be able to use the application. Since the 'admin' user has this permission we do not have to create any new users.

...

    1. location :- This will be the location that is the default base directory for the server.

...

    1. mount-point :- This is the URL used to access this resource. in this case it would be localhost:8080/practice.

...

    1. app-bar-display :- This will let OFBiz know if we want our component to show up in the main application tabs that are part of the common ofbiz decorator.

...

Creating the web app

Step - 1 : Create a "webapp" directory in the practice component (hot-deploy/practice/webapp).
This directory contains all the webapp related files for the component we are creating.
Step - 2 : Create a sub-directory inside the webapp directory by the name of  "practice" which is the name of the webapp which you are going to develop (hot-deploy/practice/webapp/practice). A component can have multiple webapps attached to it. e.g. In the "marketing" component there are two webapps "marketing" and "sfa".
The webapp we are creating will follow the J2EE webapp standards.
Step - 3 : Create WEB-INF directory in your webapp (hot-deploy/practice/webapp/practice/WEB-INF).
An OFBiz web application requires two configuration files, a controller.xml and a web.xml. The controller.xml tells OFBiz what to do with various requests from visitors: what actions to take and what  pages to render. web.xml tells OFBiz what resources (database and business logic access) are available for this web application and how to handle web-related issues, such as welcome pages, redirects, and error pages.
Step - 4 Create a file named "web.xml"(web.xml follows j2ee webapp specs). Contents of this file can be copied from any of the existing component e.g. /framework/example component. The Important values to change are the <display-name>, the localDispatcherName, the mainDecoratorLocation and the webSiteId.

...