Hello Danny,
 
I'm not 100% sure, but as far as I understood ActionListeners and
managed-beans are not the same this, so the aren't created by the same
Factory.
Therefor it would logical to have different instances of the class.
 
I didn't try it with ActionListeners yet, but I did ran into the same
sort of problems with ServletFilter, which are being instanciated by the
servlet-container and not 'properly' retrieved from an IoC-container
causing the dependancy injection to not be executed. Since the lifecycle
of an ActionListeren doesn't have any init-method or something alike I
suggest you do the following:
 
1) Add a boolean isInitialized = false;
2) In the implementation of processAction(javax.faces.event.ActionEvent
event) method check if object isInitialized. If not run a custom
initListener-method()
3) Write the custom initListener, which retrieves the dependancues from
the IoC-container you are using. For Spring this would be something
like:
private void initListener() {
  ServletContext servletContext = (ServletContext)
FacesContext.getCurrentInstance().getExternalContext() 
  BeanFactory beanFactory =
WebApplicationContextUtils.getWebApplicationContext( servletContext  );
  myService = (ServiceInterface) beanFactory.getBean( "serviceId" ); 
}


I hope this helps get you your ActionListener working.

 

With kind regards,
  Marco

 
________________________________

From: Worm, Danny [mailto:[EMAIL PROTECTED] 
Sent: donderdag 18 januari 2007 10:12
To: users@myfaces.apache.org
Subject: Depency Injection



Hi,

I want to use my ActionListener as a Managed-Bean because I need to
inject a service to the listener. 

In the invoke-application-phase the injected service is null, why?

So I added a breakpoint to the setter of the property. And so the setter
will be invoked, but the JavaObject-ID isn't the same as in Phase 5!

Does the managed-bean factory create a proxy for the managed-beans or
listener-classes?

Where is the break in my mind?

Thanks

kind regards

DaWorm

 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
New Jersey, USA 08889), and/or its affiliates (which may be known
outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD
and in Japan, as Banyu - direct contact information for affiliates is 
available at http://www.merck.com/contact/contacts.html) that may be 
confidential, proprietary copyrighted and/or legally privileged. It is 
intended solely for the use of the individual or entity named on this 
message. If you are not the intended recipient, and have received this 
message in error, please notify us immediately by reply e-mail and then 
delete it from your system.

------------------------------------------------------------------------------

Reply via email to