Versions Compared

Key

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

This page is intended to be the root of Cookbook, FAQ, Tips, Tricks, HowTo, etc.
You may find supplementary useful informations at Old OFBiz wiki and Opentaps's OFBiz cookbooks part but not note that this information may be outdated...

...

RMI

  • This RMI error on client side?, click to see the tip

    Code Block
    
    Caused by: java.util.MissingResourceException: Can't find bundle for base name cache, locale en_US
    

...

Uncomment (or compile with at least these modules using --enable on Debian/Ubuntu use a2enmod)

Code Block

#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule ssl_module modules/mod_ssl.so

...

Add something like

Code Block

ProxyRequests Off

<Proxy *>
        AddDefaultCharset off
        Order deny,allow
        Allow from all
</Proxy>

# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off \| On \| Full \| Block
ProxyVia On

NameVirtualHost *:80

<VirtualHost *:80>
    #   General setup for the virtual host.
    ServerName www.example.com:443
    ServerAdmin you@example.com

    ProxyRequests Off
    ProxyPreserveHost On
    proxyPass / ajp://localhost:8009/

    RewriteEngine On
    RewriteRule ^/(images/.+);jsessionid=\w+$ /$1

</VirtualHost>

include conf/httpd-ssl.conf
(or include ../apache2/httpd-ssl.conf if using a file in sites-available on Debian/Ubuntu using a2ensite)

...

replace (according to your setup, ie. keeping the right paths)

Code Block

<VirtualHost _default_:443>

#   General setup for the virtual host
ServerName www.example.com:443
ServerAdmin you@example.com

by

Code Block

<VirtualHost *:443>
    ServerName www.example.com:443
    ServerAdmin you@example.com

    ProxyRequests Off
    ProxyPreserveHost On
    proxyPass / ajp://localhost:8009/

    RewriteEngine On
    RewriteRule ^/(images/.+);jsessionid=\w+$ /$1

for apache 3.2.2 servers youu need to add

Code Block

    SSLEngine on
    SSLProtocol all -SSLv2
     SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
     SSLCertificateFile /etc/pki/tls/certs/localhost.crt
     SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
ofcourse if you have a certificate for your domain you should replace
the crt and key files of your domain files.

...

Sometime it is useful to let Apache Web Server to serve the static resources such as images, css, js etc for performance or other reasons.
In that scenario, you will need to mount the individual OFBiz application. For example:
Mounting OFBiz application as show below will forward every request to OFBiz including request for static resources such as images.

Code Block

proxyPass / ajp://localhost:8009/

To mound individual application, use the below mentioned method. You will need to do this for all your application accept the one you want to be served by Apache Web Server e.g. /images

Code Block

<Location /accounting/>
       ProxyPass ajp://localhost:9009/accounting/
 </Location>

Configure the Images folder in the Apache as shown below:

Code Block

<Directory /var/www/xxxx/images/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Order allow,deny
       allow from all
    </Directory>

...

I you need to use an svn repository on the same server the tip is to add

Code Block

proxyPass /svn !

just before

Code Block

proxyPass / ajp://localhost:8009/

...

To patch on Windows you have to download patch.exe. But you may encouter EOL problems with patch.exe. That's why I prefer to use Eclipse's "Apply Patch" option wich is great to use with clipboard. If you get issue with Subclipse and work on Windows you may try Tortoise's "Apply Patch" option. If I get problems with Tortoise I then use the patch command. Something to understand is that Tortoise actually use "SVN merge" so in certains cases problems arise. To avoid EOL problems with the patch command, I use a bat file patchdos.bat :

Code Block

todos %1
patch -N -p0 < %1

...

  • You need JavaService.exeThis is freely available at http://javaservice.objectweb.org/.
    Documentation and example code are also available
    Unzip the JavaService-bin-1.2.x.zip (or JavaService-2.0.x.zip)
  • Where should the expanded files be located?
    Set up and run your script with the appropriate path. Ex:

    Code Block
    
    javaservice -install OFBiz %java_home%\jre\bin\server\jvm.dll -Xms256M -Xmx512M
    -Djava.class.path=%java_home%\lib\tools.jar;%ofbiz_home%\ofbiz.jar
    -start org.ofbiz.base.start.Start
    -out %ofbiz_home%\logs\serviceLog.txt
    -err %ofbiz_home%\logs\serviceErr.txt
    -current %ofbiz_home%
    -manual
    

...

Here an example based on one of my test (http://labs.libre-entreprise.org/scm/viewvc.php/ofbizNeogia/neogia/manufacturing/webapp/manufacturing/tests/TestCreateNomenclature.html?revision=1.10&root=neogia&view=markup)

Code Block

<!-- create a variable named uid that contains an unique identifier -->
<tr>
       <td>store</td>
       <td>javascript{(new Date()).getTime() % 10000}</td>
       <td>uid</td>
</tr>
Code Block

<!-- use of the variable named uid to fill a form entry -->
<tr>
       <td>type</td>
       <td>partyId</td>
       <td>user-${uid}</td>
</tr>

3) What is the difference between click and clickAndWait ? I would like to understand why I'm getting different behaviors from click and clickAndWait functions. Here is the scenario: I want to perform the login and then verify some text on the page (what should be pretty straight forward...) My first approach was using the clickfunction + pause function. Something like below:

Code Block

<tr>
    <td>click</td>
    <td>submit</td>
    <td></td>
</tr>
<tr>
    <td>pause</td>
    <td>3000</td>
    <td></td>
</tr>

The approach above worked fine and I was able to proceed with my test. However, I was looking the clickAndWait functionality and, per my understanding, this function should have a simlar behavior to my code above.. then I wrote the following:

Code Block

<tr>
    <td>clickAndWait</td>
    <td>submit</td>
    <td></td>
</tr>

...

I think the right solution is to use clickAndWait command instead of click+pause because it always success contrary to click+pause (we dont known the page response time). I see no reason why you don't observe the same behavior with clickAndWait. Maybe it's because your are testing the login page that can be a little tricky to test due to the session handling.
To be sure to always start a test in a clean session, my tests always do the same actions :
1. logoff
2. login
3. check error
Here, an example of my standard login procedure under selenium from (http://labs.libre-entreprise.org/scm/viewvc.php/ofbizNeogia/neogia/manufacturing/webapp/manufacturing/tests/TestCreateNomenclature.html?root=neogia&view=markup)

Code Block

<!-- Begin of standard login procedure -->
<tr>
 <td>open</td>
 <td>/manufacturing/control/logout</td>
 <td></td>
</tr>
<tr>
 <td>type</td>
 <td>USERNAME</td>
 <td>admin</td>
</tr>
<tr>
 <td>type</td>
 <td>PASSWORD</td>
 <td>ofbiz</td>
</tr>
<tr>
 <td>select</td>
 <td>locale</td>
 <td>value=fr</td>
</tr>
<tr>
 <td>clickAndWait</td>
 <td>submitButton</td>
 <td></td>
</tr>
<tr>
 <td>assertElementNotPresent</td>
 <td>//div[@class='errorMessage']</td>
 <td></td>
</tr>
<!-- End of standard login procedure -->

...

Add a entity-resource entry of type "data" and reader-name as "ext" in ofbiz-components.xml of your application. For example:

Code Block

<entity-resource type="data" reader-name="ext" loader="main" location="data/GeoData_IN.xml"/>

And run the

Code Block

"run-install-extseed"

ant target instead of

Code Block

"run-install"

This should load your modified data along with the seed data and without any demo data.

...

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/speciapurpose/myapp/build.xml
ofbizhome/speciapurpose/myapp/ofbiz-component.xml
ofbizhome/speciapurpose/myapp/webapp/myapp/WEB-INF/controller.xml
ofbizhome/speciapurpose/myapp/webapp/myapp/WEB-INF/web.xml
ofbizhome/speciapurpose/myapp/webapp/myapp/index.jsp

...

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)

...

Add the $OFBIZ/framework/base/config dir to the jar as a <resource> in your build file (Maven's pom.xml example, to be adapted for ant)

Code Block

<resources>
      <resource>
        <directory>../../../framework/base/config</directory>
      </resource>
      <resource>
        <directory>../../../framework/base/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/datafile/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/entity/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/entityext/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/minilang/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/security/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/service/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/widget/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/workflow/dtd</directory>
      </resource>
      <resource>
        <directory>../../../framework/applications/content/dtd</directory>
      </resource>
    </resources>

...

By default, since OFBIz is under the Apache Software Fundation Licence, OFBiz comes with RMI using SSL. Before it was possible to use RMI without SSL. But due to licence constraint some code has been removed. If you need, for testing for instance, to use RMI without SSL follow this tip:
In framework/base/config/ofbiz-containers.xml comment out this snippet during tests

Code Block

<property name="client-factory" value="org.ofbiz.service.rmi.socket.ssl.SSLClientSocketFactory"/>
<property name="server-factory" value="org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory"/>
<property name="ssl-keystore" value="framework/base/config/ofbizrmi.jks"/>
<property name="ssl-keystore-type" value="JKS"/>
<property name="ssl-keystore-pass" value="changeit"/>
<property name="ssl-keystore-alias" value="rmissl"/>
<property name="ssl-client-auth" value="false"/>

OR

  1. In framework/base/config/ofbiz-containers.xml replace (or better comment out during tests)

    Code Block
    
    <property name="client-factory" value="org.ofbiz.service.rmi.socket.ssl.SSLClientSocketFactory"/>
    <property name="server-factory" value="org.ofbiz.service.rmi.socket.ssl.SSLServerSocketFactory"/>
    

    by

    Code Block
    
    <property name="client-factory" value="org.ofbiz.service.rmi.socket.zip.CompressionClientSocketFactory"/>
    <property name="server-factory" value="org.ofbiz.service.rmi.socket.zip.CompressionServerSocketFactory"/>
    
  2. Unzip in framework\service\src\org\ofbiz\service\rmi\socket\zip the content of this attachment

...

For that simply uncomment these lines in startofiz.sh

Code Block

IPADDR=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
RMIIF="-Djava.rmi.server.hostname=$IPADDR"

...

If you get accounting related issues and are not interested in posting accounting transactions

  1. If you are not interested in posting accounting transactions to the GL then you can disable (i.e. comment out) the first eca rule in accounting/servicedef/secas_ledger.xml

    Code Block
    
    <eca service="createAcctgTransAndEntries" event="commit">
        <condition field-name="acctgTransId" operator="is-not-empty"/>
        <action service="postAcctgTrans" mode="sync"/>
    </eca>
    

...

You can use TTF fonts in fo.ftl files. You need to use file "framework/webapp/config/fop.xconf". This file contain following code that responsible for font family, change font family according to the requirement, exemple

Code Block

<font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
  <font-triplet name="Arial" style="normal" weight="normal"/>
  <font-triplet name="ArialMT" style="normal" weight="normal"/>
</font>

I found that I could put this:

Code Block

<fonts>
  <auto-detect/>
</fonts>

...

Anchor
ValidationInForms
ValidationInForms

Validation in forms

  1. include a js code like below:

    Code Block
    
    Event.observe(window, 'load', function() {if ($('formId'))  validateNewUser = new Validation('formId', {immediate: true});}
    
  2. And in the respective form use the suitable class for form fields

    Code Block
    
    <field ... widget-style="required"> ... </field>
    <field ... widget-style="validate-email"> ... </field>
    <field ... widget-style="validate-url"> ... </field>
    

...