Matt Tyson wrote:
Can you have a phase listener entry in the config.xml be a managed bean
reference?
I've got a phase listener that needs a reference to another object to get
some data and I want to externalize that reference.

Not as far as I know. I would also love this to be possible in order to pass configuration data to phase listeners but haven't figured out how.

Of course, you do mean an application-scope managed bean, yes? No other scope makes sense as phase listeners are global for a webapp.

It is possible to create a class that registers itself as a PhaseListener when an instance is created. However if this is listed as an application-scope managed bean, then it doesn't get created until something references it from a page. It would be wonderful if there was some "lazy-init=false" option for application-scope managed beans to force them to be created on webapp startup but this doesn't exist AFAIK.

As the app I'm currently working on uses Spring, I declare a Spring singleton bean which explicitly looks up the Lifecycle, gets the phase listener list, searches it for an instance of my phase listener type, then calls setter methods to push the config data defined in the spring file into the phase listener. Spring singletons are created when spring is initialised (which is just after JSF is initialised). This implementation is not terribly clean or intuitive so if anyone has alternate suggestions I'd be keen to hear them..

Regards,

Simon

Reply via email to