Versions Compared

Key

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

...

...

From a thread by Chris Howe and David Jones
Chris Howe: Lets say that I want to create an application that most closely matches the ecommerce app. I should start with copied versions the following files only.

Code Block
ofbizhome/hot-deployspeciapurpose/myapp/build.xml
ofbizhome/hot-deployspeciapurpose/myapp/ofbiz-component.xml
ofbizhome/hot-deployspeciapurpose/myapp/webapp/myapp/WEB-INF/controller.xml
ofbizhome/hot-deployspeciapurpose/myapp/webapp/myapp/WEB-INF/web.xml
ofbizhome/hot-deployspeciapurpose/myapp/webapp/myapp/index.jsp

...

web.xml:
change display name and description from "ecommerce"
to "myapp"

Then change hot-deployspeciapurpose/component-load.xml to load
"myapp"

...

David Jones: Yes, this is the best practice... Being able to do this is part of the design and intention of the screen widget. BTW, the hot-deploy directory is may be easier to use than the special-purpose speciapurpose directory, but of course you can mount a component from anywhere .(the following paragraph explains with more details)

Anchor
BestPracticeCustomWebApp
BestPracticeCustomWebApp

How to Extend an existing component in customized application?

Scenario : For any customized application under hot-deploy if it is needed to extend the existing component then changes in following files are required.

(For instance we are extending the Marketing component.)
1) Inside webapp of your customize application create a folder for component name. (marketing/WEB-INF)
2) Add controller.xml, web.xml
3) In controller.xml file include the <include location="component://marketing/webapp/marketing/WEB-INF/controller.xml"/>
4) In ofbiz-component.xml (hot-deploy/customize_project/)
add following code :
<webapp name="marketing" title="Marketing-Customized" server="default-server" location="webapp/marketing" base-permission="OFBTOOLS,MARKETING" mount-point="/marketing"/>
(extending marketing component here.)Now here the basic setup for extend the component is completed, now you can add component specific request and view in controller.xml here. And create screens in the extanded componint. Note : Please add if some of the information is missing here.

What is considered the best practice in creating a custom web application with OFBIZ?

One approach is to simply copy an entire component into a new directory and start hacking away at it until it fit your needs. This is a fine practice if you never have plans of bringing it up to date with a current revision or version. OFBIZ is currently making about 40 commits a week. By the time you complete your customizations, you are out of date.

Another approach is to make adifferences web app. This is where you copy the five essential files from a similar application that is being maintained by the project, make minor modifications to them.

Which one is right? It depends on on how much changes you are making. Modifying the following files will allow you to "customize" an application, whereas starting from scratch using an existing application as a template is better for a "custom application."

The Five Files

  • application\...\webapp\...\WEB-INF\controller.xml
    • <web-app>
      • change the <display-name>
      • change the <description>
  • application\...\webapp\...\index.jsp
    • change nothing
  • applicaton\build.xml
    • <project>
      • change the name
    • <target name="init">
      • change value of property "desc"
      • change value of property "name"
    • <target name="classpath">
      • ensure all fileset dir are correctly relative to the location of your app
  • application\ofbiz-component.xml
    • <ofbiz-component>
      • change the name
    • <webapp>
      • change the name
      • change the title
      • change the location
      • change the mount point

Now if you were to start OFBIZ and point your browser to mydomain.com/myapp you would see an exact duplicate of the application that you were modeling.

From there you need to understand how a page is rendered. It is more detailed than this, but this explanation will suffice for the majority of simple customizations.

  1. Client makes a request
  2. request (among other things) calls a view (controller.xml)
  3. view calls a screen (controller.xml)
  4. screen (Screens.xml) calls some actions and widgets (.bsh, *Forms.xml, *.ftl, etc)
  5. the page is rendered to the client.

The goal with the differences app is to create all of the customizations that you need without touching original OFBIZ code. That way when you update to more current versions, you're less likely to encounter significant conflicts. It makes your application close to being "turn-key".

The Decorator

Most likely the first thing your're going to want to customize is the decoration (the header, which screens are in the leftbar if you want to display a right bar, how the body is displayed, which UILabels you use, etc). For this you need to do two things. (As of revision 5539 you can only do this if your views are using the ecommerce application, it shouldn't be long before all of the applications support this)

  • Change the location of the mainDecoratorLocation in web.xml
    Code Block
    
    <context-param>
        <param-name>mainDecoratorLocation</param-name>
        <param-value>component://ecommerce/widget/CommonScreens.xml</param-value>
        <description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description>
    </context-param>
    
  • Create a screen with name="main-decorator" in the file you specified in the mainDecoratorLocation property (I imagine you'll want to copy an existing decorator screen and modify it rather than start from scratch)

Now your application is an exact copy of the model application with your customized decoration. The reason it's an exact copy is because you have essentially the same controller.xml files in both applications. All of the requests call the same views, which call the same screens, which in turn call the same actions and widgets. So now you want to make some more changes.

Customize Screens

  • controller.xml
    • <view-map>
      • change the name if necessary
      • change the location to a *Screens.xml file inside custom application
  • *Screens.xml
    • create a new screen
    • remember they can call .bsh, .ftl, and forms from other applications
    • if you want to use a custom .ftl or .bsh be sure to us a similar directory structure as the original file so you can make easy comparisons when you update.

That's really all there is to it. If you call new services from the requests, make sure you create your file in component://myapp/servicedef/services.xml and make sure it gets loaded in the ofbiz-component.xml file. Same with ECAs. Need new classes, create them in your src directory and don't forget to build them with ant. Keep in mind two things and maintanence of your custom application will be easier and less error prone.

  1. REUSE REUSE REUSE. (If you don't change it, you don't have to maintain it, so don't change things just to change them)
  2. Only change copies of the OFBIZ files that are in your custom application

What is considered the best practice in creating a custom web application with OFBIZ?

A David Jones's tip
One approach is to simply copy an entire component into a new directory and start hacking away at it until it fit your needs. This is a fine practice if you never have plans of bringing it up to date with a current revision or version. OFBIZ is currently making about 40 commits a week. By the time you complete your customizations, you are out of date.

Another approach is to make a different web app. This is where you copy the five essential files from a similar application that is being maintained by the project, make minor modifications to them.

Which one is right? It depends on on how much changes you are making. Modifying the following files will allow you to "customize" an application, whereas starting from scratch using an existing application as a template is better for a "custom application."

The Five Files

  • application\...\webapp\...\WEB-INF\controller.xml
    • <web-app>
      • change the <display-name>
      • change the <description>
  • application\...\webapp\...\index.jsp
    • change nothing
  • applicaton\build.xml
    • <project>
      • change the name
    • <target name="init">
      • change value of property "desc"
      • change value of property "name"
    • <target name="classpath">
      • ensure all fileset dir are correctly relative to the location of your app
  • application\ofbiz-component.xml
    • <ofbiz-component>
      • change the name
    • <webapp>
      • change the name
      • change the title
      • change the location
      • change the mount point

Now if you were to start OFBIZ and point your browser to mydomain.com/myapp you would see an exact duplicate of the application that you were modeling.

...

From there you need to understand how a page is rendered. It is more detailed than this, but this explanation will suffice for the majority of simple customizations.

  1. Client makes a request
  2. request (among other things) calls a view (controller.xml)
  3. view calls a screen (controller.xml)
  4. screen (Screens.xml) calls some actions and widgets (.bsh, *Forms.xml, *.ftl, etc)
  5. the page is rendered to the client.

The goal with the differences app is to create all of the customizations that you need without touching original OFBIZ code. That way when you update to more current versions, you're less likely to encounter significant conflicts. It makes your application close to being "turn-key".

The Decorator

Most likely the first thing your're going to want to customize is the decoration (the header, which screens are in the leftbar if you want to display a right bar, how the body is displayed, which UILabels you use, etc). For this you need to do two things. (As of revision 5539 you can only do this if your views are using the ecommerce application, it shouldn't be long before all of the applications support this)

  • Change the location of the mainDecoratorLocation in web.xml
    Code Block
    
    <context-param>
        <param-name>mainDecoratorLocation</param-name>
        <param-value>component://ecommerce/widget/CommonScreens.xml</param-value>
        <description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description>
    </context-param>
    
  • Create a screen with name="main-decorator" in the file you specified in the mainDecoratorLocation property (I imagine you'll want to copy an existing decorator screen and modify it rather than start from scratch)

Now your application is an exact copy of the model application with your customized decoration. The reason it's an exact copy is because you have essentially the same controller.xml files in both applications. All of the requests call the same views, which call the same screens, which in turn call the same actions and widgets. So now you want to make some more changes.

Customize Screens

  • controller.xml
    • <view-map>
      • change the name if necessary
      • change the location to a *Screens.xml file inside custom application
  • Screens.xml
    • create a new screen
    • remember they can call .bsh, .ftl, and forms from other applications
    • if you want to use a custom .ftl or .bsh be sure to us a similar directory structure as the original file so you can make easy comparisons when you update.

...

That's really all there is to it. If you call new services from the requests, make sure you create your file in component://myapp/servicedef/services.xml and make sure it gets loaded in the ofbiz-component.xml file. Same with ECAs. Need new classes, create them in your src directory and don't forget to build them with ant. Keep in mind two things and maintanence of your custom application will be easier and less error prone.

  1. REUSE REUSE REUSE. (If you don't change it, you don't have to maintain it, so don't change things just to change them)
  2. Only change copies of the OFBIZ files that are in your custom application

Anchor
ExtendExistingComponent
ExtendExistingComponent

How to Extend an existing component in customized application?

Scenario : For any customized application under hot-deploy if it is needed to extend the existing component then changes in following files are required.

(For instance we are extending the Marketing component.)
1) Inside webapp of your customize application create a folder for component name. (marketing/WEB-INF)
2) Add controller.xml, web.xml
3) In controller.xml file include the <include location="component://marketing/webapp/marketing/WEB-INF/controller.xml"/>
4) In ofbiz-component.xml (hot-deploy/customize_project/)
add following code :
<webapp name="marketing" title="Marketing-Customized" server="default-server" location="webapp/marketing" base-permission="OFBTOOLS,MARKETING" mount-point="/marketing"/>
(extending marketing component here.)Now here the basic setup for extend the component is completed, now you can add component specific request and view in controller.xml here. And create screens in the extanded componint. Note : Please add if some of the information is missing here.A David Jones's tip

Anchor
HowToSetSSL
HowToSetSSL

...