Search code examples
jsf-2primefacesclassloaderwebsphere-8

Customising org.primefaces.component.messages.MessagesRenderer


Background

We have an on-line application using JSF2.0 (One that comes with Web-sphere application server v8.5.5) + PrimeFaces 5.0

Requirement

For a particular requirement, we have to customise org.primefaces.component.messages.MessagesRenderer. We noticed that there is no clean way to customise org.primefaces.component.messages.MessagesRenderer . As a work around we created a class org.primefaces.component.messages.MessagesRenderer in Web Source folder. This class ends up in WebInf/classes

Issue

Upon initial deployment prime-faces.jar loaded the version of org.primefaces.component.messages.MessagesRenderer in WebInf/classes and every thing worked as expected. Upon further investigation it became apparent that the war class loading behaviour is inconsistent. We couldn't guarantee which version of org.primefaces.component.messages.MessagesRenderer is loaded by the Prime Faces frame work. At times the application loads the version of org.primefaces.component.messages.MessagesRenderer from WebInf/classes other times it loads the version from WebInf/lib/primefaces-5.0.jar

The Servlet3.0 clearly states

The Web application class loader must load classes from the WEB-INF/classes Directory first, and then from library JARs in the WEB-INF/lib directory.

So not sure why we are experiencing this inconsistent behaviour.

What was tried & suggested

  • We tried referencing the org.primefaces.component.messages.MessagesRenderer in servlet startup listener.

  • One of my colleagues suggested to remove org.primefaces.component.messages.MessagesRenderer in primefaces jar file. This would resolve the issue, but customising third party library is against our company policy.

Summary

In conclusion what we are really looking is for a way to customise org.primefaces.component.messages.MessagesRenderer in prime-faces without patching the primefaces jar file.


Solution

  • Just found an solution for this issue

    Adding the following snippet of code in applications faces-config.xml allows me to override the MessageRenderer in primefaces

       <renderer>
            <component-family>org.primefaces.component</component-family>
            <renderer-type>org.primefaces.component.MessageRenderer</renderer-type>
            <renderer-class>my.CustomRenderer</renderer-class>
        </renderer>