0

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.

Sajeev
  • 818
  • 7
  • 23
  • 1
    Create your own component that extends the PF one? But I'd personally fix the weird WebSphere behaviour. (maybe by patching the JSF version (JSF 2.0 is not a real implementation/version, it is an spec one) – Kukeltje Apr 26 '16 at 07:37
  • 1
    Off-topic: it is PrimeFaces, not Prime Faces, prime-faces or primefaces ;-) – Kukeltje Apr 26 '16 at 07:38
  • Thanks @Kukeltje . yes it looks like a web-sphere class loading problem (not as per servlet spec) . Raising a PMR will take long to address. So I was keen on a work around, where I can manage this situation. – Sajeev Apr 26 '16 at 08:21
  • 1
    Then 'create your own component that extends...' is the way to go I think – Kukeltje Apr 26 '16 at 08:31
  • I will give it a go. Thank you – Sajeev Apr 26 '16 at 08:32
  • @Kukeltje Thanks for the effort. Just figured out a work around for the issue. – Sajeev Apr 26 '16 at 08:56
  • Ahhhhhh... yes that was what I was looking for to... Did not search to good obviously – Kukeltje Apr 26 '16 at 08:58

1 Answers1

0

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>
Sajeev
  • 818
  • 7
  • 23