6

I have a JSF 2 application that includes a jar file which in turn contains a faces-config.xml in its META-INF directory. The faces-config.xml contains a declaration of a phase-listener. I would like to prevent the installation of this phase listener without modifying the jar file itself. Is this possible?

cyberoblivion
  • 669
  • 7
  • 23

1 Answers1

4

You can't block specific parts of faces-config.xml in a 3rd party JAR from being interpreted.

You have basically 2 options:

  1. Block the whole faces-config.xml in a 3rd party JAR from being interpreted by adding metadata-complete="true" to webapp's own faces-config.xml.

    <faces-config ... metadata-complete="true">
    

    Note that this also skips annotation scans in classes of the 3rd party JAR. You'd basically need to redefine specific parts you'd like to use in webapp's own faces-config.xml.


  2. Provide a custom Lifecycle implementation via LifecycleFactory which you register in <factory><lifecycle-factory> of webapp's faces-config.xml. In that implementation, override addPhaseListener() accordingly to perform e.g. an instanceof check before skipping or continuing.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • option 2 is probably the simplest thing for me considering there are multiple other 3rd party library's I want to behave properly. – cyberoblivion Mar 22 '13 at 15:48
  • A third option, beyond your control, would be to post a feature request to the library vendor that the phase listener should skip its job when e.g. a certain context parameter, or request parameter, or session attribute, or even an environment variable is present, depending on the phase listener's actual job/responsibility. – BalusC Mar 22 '13 at 15:52