You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "Worm, Danny" <Da...@c1-fincon.de> on 2007/01/18 10:11:52 UTC
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
[tobago] f:selectItem with tc:selectOneChoice
Posted by "Wong, Emmanuel (Sam)" <Wo...@SEC.GOV>.
Hi:
Could anyone tell me how to display a specified drop down
list value? Let say will would like to display "3:Medium" instead of
other drop down value. Please see below. Thanks.
For example:
On the JSP:
< tc:selectOneChoice
value= "#{ MyClassController.myBean.probability}"
required= "false">
<f:selectItems value="#{
MyClassController.probability}" />
</ tc:selectOneChoice >
On the Backing Bean:
public class MyClassController{
private MyBean myBean;
public SelectItem[] _probability;
public SelectItem[] getProbability() {
SelectItem[] selectItemArry = new SelectItem[4];
selectItemArry[0] = new SelectItem("0" , "");
selectItemArry[1] = new SelectItem( "5", "5:High" );
selectItemArry[2] = new SelectItem( "3", "3:Medium" );
selectItemArry[3] = new SelectItem( "1", "1:Low" );
}
}
Public class MyBean{
Private int probability;
public int getProbility() {
Return probability;
}
Public void setProbility(int probility) {
This.Probility = probility;
}
}
RE: Depency Injection
Posted by "Beelen, Marco" <ma...@merck.com>.
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:Danny.Worm@c1-fincon.de]
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.
------------------------------------------------------------------------------