Tuesday Apr 06, 2010

RichFaces and Prototype - how to avoid problems

Today I have had a strange problem with my RichFaces web application. In some cases widgets did not work as expected. For example the calendar components did not work - sometimes. The reason was the HTML design template I used. The template was provided by my customer and includes a lot of CSS and also javaScript pages. One of the JavaScirpt pages was a prototyp.js library (v 1.6.0.3).

And as RichFaces (3.3.3) is also using this protype version the libraries conflicts to each other.  But when I removed the prototype.js library form my template I run into the next problem. Now the JavaScript Navigationbar-provided by the customers HTML template - did no longer work. The reason was that RichFaces did not load all scripts per default but on demand. So in complex pages with a lot of RichFaces Widges everything works fine - the NavigationToobar loads. But in a simple welcome page my Navigationbar was missing the prototype scripts and throws an javascript error (method not found).

To solve this problem and also avoid the conflict of the RichFaces Prototype Library with an external Prototype library you can use the RichFaces config Param: org.richfaces.LoadScriptStrategy

If you set this param to "ALL" all scripts will be loaded in every page - so my external navigation bar was now happy with the prototype scripts provided by richtfaces.

So now I use the following setting in my web.xml file:

    <context-param>
        <param-name>org.richfaces.LoadScriptStrategy</param-name>
        <param-value>NONE</param-value>
    </context-param>