You are previewing Apache OFBiz Development.
O'Reilly logo
Apache OFBiz Development

Book Description

Using Services, Entities, and Widgets to build custom ERP and CRM systems

  • Understand how OFBiz is put together

  • Learn to create and customize business applications with OFBiz

  • Gain valuable development and performance hints

  • A fully illustrated tutorial with functional step-by-step examples

In Detail

Apache OFBiz (Open For Business) is versatile open-source enterprise automation software that powers many small and medium sized businesses around the world. It incorporates a number of mature applications such as ERP, e-Commerce, MRP and CRM.

Built around an MVC framework with common logic, data model and process components, Ofbiz allows existing and bespoke applications to be added through a component-based architecture. Ofbiz includes a mature suite of enterprise applications that integrate and automate a company's many business needs.

This easy-to-read book will quickly enable newcomers to get hands-on with OFBiz. It provides an overview of the main modules and employs illustrated examples that show readers how to build exemplary business applications rapidly. Covering the main aspects of the Model-View-Controller framework, the reader will gain a working knowledge of Widgets, Entities, and The Service Engine. The authors also describe how to tweak OFBiz, and offer valuable performance and development tips. By navigating through the flow of OFBiz and providing insight into the thousands of examples that already exist in the core code they have made this book a must-have for anyone looking to get started with OFBiz.

Table of Contents

  1. Apache OFBiz Development
  2. Credits
  3. About the Authors
  4. About the Reviewers
  5. Preface
    1. A Brief History of OFBiz
    2. About This Book
    3. What This Book Covers
    4. What You Need for This Book
    5. Who is This Book For
    6. Conventions
    7. Reader Feedback
    8. Customer Support
      1. Downloading the Example Code for the Book
      2. Errata
      3. Piracy
      4. Questions
  6. 1. Getting Started with OFBiz
    1. Getting the OFBiz Code
    2. Downloading and Installing SVN
      1. Downloading TortoiseSVN
      2. Using SVN to Get OFBiz
        1. Our OFBiz Workspace—First Look
    3. Installing the Java Development Kit (JDK)
        1. Downloading JDK 5.0
        2. Installing JDK 5.0
    4. Downloading OFBiz Ready to Launch
    5. Setting Up an Eclipse Project
    6. Using Derby—the OFBiz Stock Database
      1. Compiling OFBiz and Loading the Data
      2. Verifying the Installation Process
        1. The Compilation Portion
        2. The Data Loading Portion
        3. Some Pre-Ignition Processes we won't do Twice
        4. Backing Up the Derby Data Files
    7. Running OFBiz
      1. Allocating Memory for OFBiz
        1. Starting OFBiz and Verifying the Start-Up Process
        2. Seeing the Logs in Real Time
        3. Possible Problems with Start-Up
    8. Switching Off OFBiz
    9. Our First Tour of OFBiz
      1. Accessing OFBiz
      2. Exploring the Webapp "ecommerce"
        1. Let's Buy Something
      3. Exploring the Webapp "order"
        1. Receiving Payment
        2. Fulfilling the Order
        3. Invoice Automatically Generated with Payment Applied
      4. End-to-End Tour Completed
    10. Summary
  7. 2. Working with OFBiz
    1. Adding Our First Field
      1. Changing the Data
        1. Editing the Entity Definition
      2. Updating the Database
      3. Changing the Looks
        1. Editing the User-Interface
      4. Checking Our Changes
      5. Changing the Flow
        1. Rewiring the "Save" (Update Postal Address) Button
        2. Creating the New Widget Screen
        3. Creating the FTL File
          1. Checking Our New Wiring
        4. More to the Flow
          1. Creating the Wiring for Preprocessing
          2. Creating the Preprocessing
          3. Testing Our Smarter Wiring
      6. Some Changes Possible with Engines Running
    2. Resetting Our Play Area Quickly
      1. Skipping Some Pre-Ignition Processes
        1. Restoring Derby Data Files
        2. Removing the Web Server (Catalina) Work Files
        3. Updating the Database with Our Data Entity Changes
      2. Showing Off Our Spanking New OFBiz Installation
        1. Tripping Up Our Plan
      3. Storing a Save-Point to Dramatically Ease Testing
        1. Archiving Derby Data Files and Web Server Work Files
          1. Backing Up the Derby Data Files
          2. Backing Up the Web Server Work Files
          3. Computer, Run Scenario B that Mr. Evaluator just Described
      4. Restoring a Save-Point
        1. Restoring the Derby Data Files
        2. Restoring the Web Server Work Files
        3. Computer, Run Scenario A from Last Save-Point
    3. The Structure of OFBiz in General
      1. Components in OFBiz
      2. Referencing Components in OFBiz
      3. Creating Our Own OFBiz Component
        1. Creating the Component
      4. Using Our Component
        1. Cleaning Up Our Mess in the "party" Component
      5. Converting the BeanShell to a Java Event
        1. Clean Extension Strategies Employed
        2. Checking that Our Move was Successful
        3. A Bit More Mess Remains
      6. Webapps in OFBiz
        1. Creating Our First Webapp
        2. Webapp URIs in this Book
        3. Testing Our First Webapp
    4. The Model-View-Controller Architectural Pattern
      1. The MVC in Plain English
        1. The Model in OFBiz
        2. The View in OFBiz
        3. The Controller in OFBiz
        4. Other Files in an OFBiz Component
    5. Summary
  8. 3. Screen Widgets
    1. Equipping Our Webapp with a Screen Widget View Handler
    2. Using the Screen Widget View Handler
    3. Files and Locations
    4. Creating Our First Screen Widget
      1. Defining a Screen Widget
      2. Informing the Control Servlet about the Screen Widget
      3. Referencing Screen Widgets
      4. Uniform Pattern of Flow in OFBiz
      5. Seeing Our First Screen Widget
    5. The Anatomy of the <section> Element
      1. Our First Conditional Screen Widget
      2. Element Order in the controller.xml
      3. Inform the Control Servlet about the Screen Widget
      4. If-Then-Else Structure
        1. The <if-condition> Element
        2. The Then—<actions> and <widgets> Elements
          1. The <actions> Element
          2. The <widgets> Element
        3. The Else—<fail-widgets> Element
        4. The Minimum <section>
      5. Sending Parameters with Requests
      6. Seeing Our Conditional Screen Widget
      7. Screen Widget Context and Variables
        1. Utility Objects in Context
          1. Utility Objects—Brief Explanation
          2. The Local (Private) Context
          3. Loosely Typed Variables in BeanShell
          4. Literals Versus Variables
          5. Accessing Variables' Values
          6. Accessing Map Variables' Values
          7. The Global Context
    6. Nested Sections for Nested Conditions
    7. Organizing a Large Screen into Smaller Screens
      1. The Global Context Revisited
      2. Outer Contexts Visible to Nested Ones
    8. Screen Widget's Integration with FreeMarker
    9. Cleaning Up in the "party" Component
    10. Commenting Changes to the Core Code
    11. Screen Widgets as Templates
      1. A Candidate for Templating
        1. Creating the Header
        2. Creating the Footer
        3. Using Our Header and Footer
        4. Seeing Our First Well-Formed XHTML Document
      2. Using Decorator Screen Widgets for Templating
        1. Creating a XHTML Decorator Screen
        2. Using the XHTML Decorator Screen
        3. Seeing Our First Decorator in Action
      3. Multiple Content Slots
        1. Creating the First Half of the Header
        2. Creating the Second Half of the Header
        3. Adding a Content Slot to a Decorator
        4. Using Our Multi-Slot Decorator
        5. Seeing Our First Multi-Slot Decorator
      4. Nesting Decorators
        1. Top-Down Approach (delegation)
        2. The Bottom-Up Approach (Vertical Stack)
        3. Using Both Approaches
    12. Summary
  9. 4. Form Widgets
    1. Files and Locations
    2. Creating Our First Form Widget
      1. Creating the Containing Screen Widget
      2. Referencing Form Widgets
      3. Create the Form Widget
      4. Seeing Our First Form
      5. Understanding the Form Attributes
        1. Minimum Requirements to Use Form Widgets
          1. The CSS StyleSheet maincss.css
          2. The JavaScript Library selectall.js
        2. Including the Minimal Requirements
    3. Form Processing via Request Event
    4. Java Events
    5. Submitting and Processing Our First Form
    6. The "list" Type Form Widget
      1. Creating the Containing Screen
      2. Adding Form Processing Code
      3. Publishing the Form
      4. Seeing Our First "list" Type Form
    7. The "multi" Type Form Widget
      1. Creating the Containing Screen
      2. Loading Data for the Form
      3. Publishing the Form
      4. Creating the Form-Processing Logic
      5. Seeing Our First "multi" Type Form
    8. Alternative Targets in Two-Target Forms
      1. Creating the Form
      2. Creating the Containing Screen
      3. Publishing the Two-Target Form
      4. Seeing Our First Two-Target Form
    9. Row-Level Actions
      1. Creating the Form
      2. Creating the Containing Screen
      3. Publishing the Form
      4. Seeing the Form in Action
    10. Summary
  10. 5. Other View Element Types in Screen Widgets
    1. Menu Widgets
      1. Creating Our First Menu Widget
      2. Including Our Menu Widget in Our Screen Widgets
        1. Understanding the Menu Item Attributes
        2. Including the Menu Widget via a Decorator Screen Widget
        3. Add Screen Widget "ConditionalScreen" to the Menu
      3. Sub-Menus and Conditional-Menu Items
      4. Pre-processing Actions for Menu Widgets
    2. FreeMarker
      1. As Decorator Templates
      2. Displaying Dynamically Created List Variables
      3. Iterating Through the List
    3. Bringing it All Together
      1. The User-Interface Labels
      2. Adding the appheader
    4. Summary
  11. 6. The Controller
    1. How OFBiz Hears Our Requests—The Control Servlet
      1. Defining a Control Servlet for a Webapp
      2. Using the Control Servlet
      3. Funnelling All Requests to the Single Control Servlet
      4. Defining Needed Utility Objects for the Control Servlet
        1. GenericDelegator Object
        2. The GenericDispatcher Object
      5. Some Background on Servlets
    2. Programming a Control Servlet
      1. Logging into Our Learning Application
      2. Specifying Handlers
      3. Request Maps
        1. Knocking on the Right Doors
        2. Security—Before Answering the Door
        3. The https Attribute
        4. The auth Attribute
        5. The direct-request Attribute
      4. Event—Determining a Response
        1. Java Events
        2. Response—Defining Various Responses
          1. How a Response is Chosen
          2. Default Responses and Non-Responses
          3. Type "view" Responses
          4. Type "request" Responses
          5. Type "request-redirect" Responses
          6. Type "request-redirect-noparam" Responses
      5. View Maps
    3. Summary
  12. 7. Entities, View Entities, and Extended Entities
    1. Entities
      1. The Structure of the Data Model
      2. Referencing Fields of an Entity
      3. OFBiz Uses Relational Database Management Systems
      4. Curious Trivia about the Relational Model
      5. Entity Engine Concepts
      6. Datasources
      7. Entity Delegators
      8. Entity Groups
      9. Defining Our First Entity
      10. Assigning Our Entity to an Entity Group
      11. Loading Our Entity into the Entity Engine
      12. Seeing Our First Entity
      13. Using Our First Entity
        1. Creating a Drop-Down
        2. Populating the Drop-Down
        3. Expiring a Value
        4. Un-Expiring a Value
      14. Anatomy of an <entity> Element
        1. The <field> Element
          1. Database Independence
          2. The "type" Attribute
        2. The <prim-key> Element
        3. The <relation> Element
          1. Creating the Field that Participates in a Relation
          2. Creating the Relation
          3. Accessing the Relation
          4. Updating the Database
        4. The <index> Element
          1. Indexes on Foreign Keys
      15. Relation Types
        1. One-to-One Relations
        2. One-to-Many Relations
          1. Inverse of One-to-One Relations
        3. One-to-One Relations with No Foreign Keys
    2. View Entities
      1. Anatomy of a <view-entity>
        1. The <member-entity> Element
        2. The <alias> and <alias-all> Elements
          1. The <alias> Element
          2. Seeing the SQL Equivalent
          3. The "all including" <alias-all> Element
        3. The <view-link> Element
          1. Inner Joins versus Outer Joins
        4. The <relation> Element
      2. Applying Functions on Fields
        1. Counting the Number of Records
        2. Counting Distinct Records
        3. Arithmetic Aggregate Functions
        4. Uppercase and Lowercase Functions
      3. Grouping for Summary Views
      4. Complex Aliases
        1. Nested <complex-alias> Elements
          1. Operators are Database-Specific
    3. Extending Entities
    4. Summary
  13. 8. Accessing the Entities and View Entities
    1. Setting-Up Our Playground
      1. The Script Processor
      2. The Generic Screen
        1. Creating the Screen Widget
        2. Creating the Form Widget
        3. Creating the FreeMarker File
        4. Publishing Our Generic Screen
      3. Testing Our Playground
    2. GenericValue Objects
    3. Creating a Database Record
      1. Why a Map is Used?
    4. Updating Database Records
    5. Deleting Database Records
    6. Retrieving Database Records
      1. Find Records by Conditions
        1. Conditions
        2. Comparison Operators (EntityComparisonOperator)
          1. Single-Value Operators
          2. Set-Value Operators
          3. Text-Value Operators
        3. Condition Lists
        4. Condition Joiners (EntityJoinOperator)
          1. The AND Joiner
          2. The OR Joiner
          3. Nested Condition Lists
          4. Selecting Fields to be Retrieved
          5. Ordering the Retrieved Records
          6. Dealing with Grouped and Summary Views
      2. Tools for Common Styles of Conditions
        1. Conditions Joined by AND
          1. Special Usage with java.util.Map
            1. Ordering Retrieved Records
        2. Conditions Joined by OR
        3. Counting the Number of Records Retrieved
        4. OFBiz Date Condition
          1. Finding Records Active at this Moment
          2. Finding Records Active at Some Particular Moment
            1. UtilDateTime Class Method "toDate"
          3. Dealing with Field Names Other Than "fromDate" and "thruDate"
      3. Getting Related Records
        1. One-to-One Relations
        2. One-to-Many Relations
      4. Utilities for Post-Query processing
        1. Post-Query Ordering
        2. Post-Query Filtering by Conditions
        3. Post-Query Filtering by Date
          1. Specifying Custom fromDate and thruDate Field Names
        4. Other Post-Query Filtering Methods
          1. The filterByAnd Method
          2. The filterByOr Method
    7. Using the Entity Engine Cache
    8. Dynamic View Entities
      1. Left Outer Joins with the Dynamic View Entity
      2. Performing the Lookup
      3. EntityFindOptions
    9. Paginating Using the EntityListIterator
      1. Paginating through Party Records: A Working Example
    10. Functions and Dynamic View Entities
    11. Summary
  14. 9. The Events
    1. Java Events
      1. Security and Access Control
        1. User Logins are like Access Cards
        2. Security Groups are like Access Levels
        3. Security Permissions are like Individual Secured Areas
        4. Security Permissions are Contained within Security Groups
        5. User Logins are Assigned Security Groups
      2. Dealing with Security in Java
      3. Sending Feedback to the End-User
        1. Conventions for Message Placeholders
        2. Testing the Conventions
      4. Handling Parameters
      5. Accessing Localized Messages
        1. Parameterizing Messages
        2. Catering for Multiple Languages
    2. Working with the Database
    3. Summary
  15. 10. The Service Engine
    1. Defining a Service
    2. Creating the Java Code for the Service
    3. Testing Our First Service
    4. Service Parameters
      1. Input Parameters (IN)
      2. Output Parameters (OUT)
      3. Two Way Parameters (INOUT)
      4. Special Unchecked Parameters
      5. Optional and Compulsory Parameters
    5. The DispatchContext
    6. Service Security and Access Control
    7. Calling Services from Java Code
    8. Implementing Interfaces
      1. Overriding Implemented Attributes
    9. Synchronous and Asynchronous Services.
    10. Using the Job Scheduler
    11. Quickly Running a Service
    12. Naming a Service and the Service Reference
    13. Event Condition Actions (ECA)
      1. Service Event Condition Actions (SECAs)
      2. Entity Event Condition Actions (EECAs)
    14. Summary
  16. 11. Permissions and the Service Engine
    1. Simple Permissions
    2. Two-Part Permissions and Special "_ADMIN" Permissions
    3. Role Checks
    4. Combining Multiple Checks
    5. Nested Checks
    6. Complex Permissions
      1. Setting-Up Our Playground
        1. Creating the Request and View Maps
        2. Creating the Screen and Form Widgets
        3. Creating the Entity PlanetReview
        4. Defining Services that Require Complex Permission
        5. Implementing Services that Require Complex Permission
        6. Defining Permission Services
        7. Implementing Permission Services
      2. Playing with Complex Permissions
        1. Complex Permissions and Simple Permissions cannot be combined
    7. Summary
  17. 12. Minilang
    1. What is Minilang?
      1. Tools to Code XML
    2. Defining a Simple Service
      1. Defining the Simple Service
      2. Writing the Simple Method
    3. Simple Events
    4. Validating and Converting Fields
      1. Validating a Simple Event Example
    5. Checking Security in Minilang
    6. Invoking from Minilang
      1. Calling Services from Minilang
      2. Calling Simple Methods
      3. Calling Java Methods
      4. Calling BeanShell
    7. Minilang in Screen Widgets
    8. Summary
  18. 13. Tying Up the Loose Ends
    1. The OFBiz Look and Feel
      1. Changing the Customer Facing Site
      2. Changing the Back Office Screens
        1. The Header
        2. The Applications Bar (appbar)
        3. The Central Area
          1. The Application Header
        4. The Footer
    2. Using FreeMarker
      1. OFBiz Transform Tags
        1. <@ofbizUrl>
        2. <@ofbizContentUrl>
        3. <@ofbizCurrency>
      2. Calling Java from FreeMarker
    3. OFBiz Utilities
        1. UtilMisc
        2. UtilValidate
        3. UtilDateTime
        4. Debug
    4. Outputting Different Formats
      1. Outputting a PDF
    5. Summary
  19. 14. Tips and Techniques
    1. Debugging Techniques
      1. Logging
        1. console.log
        2. ofbiz.log
      2. Configuring the Logs
      3. Viewing the Logs through Webtools
      4. Writing Information to the Logs
      5. Logging Minilang
    2. Debugging Java Code
        1. Passing in the VM Parameters
        2. Configuring the Remote Debugger
    3. Managing a Project Using Subversion
      1. Preparing the Repository and Creating the Project
        1. Step 1: Checking Out the Latest OFBiz Code
        2. Step 2: Making a Copy
        3. Step 3: Importing Our Copy
        4. Step 4: Branching ofbiz\current to Create the Trunk
      2. Getting the Latest Features and Bug Fixes
        1. Step 5: Updating OFBiz Current
        2. Step 6: Merging Changes between Revisions of OFBiz Current into Our Project
    4. Apache HTTP Server and OFBiz using mod_proxy_ajp
      1. Installing the Apache HTTP Server
      2. What is mod_proxy_ajp?
      3. Configuring Apache HTTP Server to Use mod_proxy_ajp
      4. Configuring OFBiz to Use the AJP Connector
      5. Getting the Secure Pages to Work
        1. Configuring SSL in Apache
        2. Creating a Self-Signed SSL Certificate
        3. Going into Production
    5. Development Tips
            1. Familiarize yourself with What is there
            2. Reuse What is there
            3. Follow the Best Practices
            4. Read the Documentation and Books
            5. Subscribe to the Mailing Lists and become an Active Member
            6. Develop on a Fast Machine
            7. Contribute
    6. Summary
  20. A. Simple Method User's Guide
    1. Simple Method User's Guide
      1. Simple Method User's Guide
        1. <simple-methods>
        2. <simple-method>
          1. Attribute Information:
          2. Usage
      2. Call Operations
        1. <call-map-processor>
          1. Attribute Information
          2. Usage
        2. <call-service> / <call-service-asynch>
          1. Attribute Information
          2. Usage
        3. <set-service-fields>
          1. Attribute Information
          2. Usage
      3. Handling the Results of Service Calls
        1. <results-to-map>
          1. Attribute Details
          2. Usage
        2. <result-to-field>
          1. Attribute Details
          2. Usage
        3. <result-to-request>
          1. Attribute Details
          2. Usage
        4. <result-to-result>
          1. Attribute Details
          2. Usage
        5. <call-bsh>
          1. Attribute Details
          2. Usage
        6. <call-simple-method>
          1. Attribute Details
          2. Usage
        7. <call-object-method>
          1. Attribute Details
          2. Usage
        8. <call-class-method>
          1. Attribute Details
          2. Usage
      4. Service Operations
        1. <field-to-result>
          1. Attribute Details
          2. Usage
      5. Event Operations
        1. <session-to-field>
          1. Attribute Details
          2. Usage
      6. Environment Operations
        1. <set>
          1. Attribute Details
          2. Usage
        2. <clear-field>
          1. Attribute Details
          2. Usage
        3. <first-from-list>
          1. Attribute Details
          2. Usage
      7. Miscellaneous Entity Operations
        1. <sequenced-id-to-env>
          1. Attribute Details
          2. Usage
        2. <make-next-seq-id>
          1. Attribute Details
          2. Usage
      8. Entity Find Operations
        1. <entity-one>
          1. Attribute Details
          2. Usage
        2. <entity-and>
          1. Attribute Details
          2. Usage
        3. <entity-condition>
          1. Attribute Details
        4. Sub-Elements
        5. <condition-list>
          1. Usage
        6. <having-condition-list>
        7. <select-fields>
          1. Usage
        8. <order-by>
          1. Usage
        9. <entity-condition> complete example:
        10. <entity-count>
          1. Usage
        11. <get-related-one>
          1. Attribute Details
          2. Usage
        12. <get-related>
          1. Attribute Details
          2. Usage
        13. <order-value-list>
          1. Attribute Details
          2. Usage
        14. <filter-list-by-and>
          1. Attribute Details
          2. Usage
        15. <filter-list-by-date>
          1. Attribute Details
          2. Usage
      9. Entity Value Operations
        1. <make-value>
          1. Attribute Details
          2. Usage
        2. <clone-value>
          1. Attribute Details
          2. Usage
        3. <create-value>
          1. Attribute Details
          2. Usage
        4. <store-value>
          1. Attribute Details
          2. Usage
        5. <refresh-value>
          1. Attribute Details
          2. Usage
        6. <remove-value>
          1. Attribute Details
          2. Usage
        7. <remove-related>
          1. Attribute Details
          2. Usage
        8. <remove-by-and>
          1. Attribute Details
          2. Usage
        9. <set-pk-fields> / <set-nonpk-fields>
          1. Attribute Details
          2. Usage
        10. <store-list>
          1. Attribute Details
          2. Usage
      10. Control Operations
        1. <iterate>
          1. Attribute Details
          2. Usage
        2. <iterate-map>
          1. Attribute Details
          2. Usage
        3. <check-errors>
          1. Attribute Details
          2. Usage
        4. <add-error>
          1. Attribute Details
          2. Usage
        5. <return>
          1. Attribute Details
          2. Usage
      11. If Conditions
        1. <if-validate-method>
          1. Attribute Details
          2. Usage
        2. <if-instance-of>
          1. Attribute Details
          2. Usage
        3. <if-compare>
          1. Attribute Details
          2. Usage
        4. <if-compare-field>
          1. Attribute Details
          2. Usage
            1. <if-empty> / <if-not-empty>
          3. Attribute Details
          4. Usage
      12. Conditions:
      13. Other Operations
        1. <log>
          1. Usage
        2. <now-timestamp-to-env>
          1. Usage
        3. <now-date-to-env>
          1. Usage
        4. <set-current-user-login>
          1. Usage
        5. <calculate>
          1. Attribute Details
          2. Usage