You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kurt Edegger <ne...@edegger.com> on 2005/12/07 03:55:01 UTC

Bean definition question faces-config.xml

Hi,

I wonder if it is possible to declare the constructor of a bean in 
faces-config.xml similar to using <constructor-arg> in spring's 
configuration files.
The idea behind this is, that I'd like to inject a bean into my 
application and use a referenced bean already in the constructor.
As far as I know and encountered, first the default constructor is 
called, then the referenced beans are injected by using the 
corresponding setters, and finally the bean is used in the application 
depending of the scope.
Or is possible to use/reference Spring beans in faces-config.xml?

Thank you for your answers,

	Kurt

Re: Bean definition question faces-config.xml

Posted by Martin Marinschek <ma...@gmail.com>.
If you use the jsf-spring integration library, you can use spring
beans from JSF. Maybe this solves your problems?

regards,

Martin

On 12/7/05, Kurt Edegger <ne...@edegger.com> wrote:
> Thank you for your fast response!
>
>
> on 12/6/2005 7:39 PM Simon Kitching stated:
> > [...snip...]
> > This is definitely not a feature of the JSF specification, and MyFaces
> > can't add any new tags to the faces-config.xml file without violating
> > the spec.
> Ok, short and precise answer ;)
> > [...snip...]
> > You can also do initialisation after all the properties have been set.
> > See the FAQ entry "How do I know when a managed bean's properties have
> > all been set?".
> There's a method called initDao() in the class
> org.springframework.jdbc.core.support.JdbcDaoSupport which should be
> overwritten in a case you need to init a DAO (which is the case in my
> situation).
> But this one is not called by JSF right? So I'd need to use spring to
> construct the bean?
>
> Thank you for pointing to the FAQ - missed that one ..
>
> Take care, Kurt
> >
> > http://wiki.apache.org/myfaces/FAQ
> >
> >> Or is possible to use/reference Spring beans in faces-config.xml?
> >
> >
> > Any managed-property like:
> >   <managed-property>
> >     <name>foo</name>
> >     <value>#{someValue}</value>
> >   </managed-property>
> > simply looks for a key "someValue" in the request, session and
> > application scopes. So if your spring bean is stored in one of those
> > maps then it will be passed to the managed bean on creation.
> >
> >
> > Regards,
> >
> > Simon
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: Bean definition question faces-config.xml

Posted by Kurt Edegger <ne...@edegger.com>.
Thank you for your fast response!


on 12/6/2005 7:39 PM Simon Kitching stated:
> [...snip...]
> This is definitely not a feature of the JSF specification, and MyFaces 
> can't add any new tags to the faces-config.xml file without violating 
> the spec.
Ok, short and precise answer ;)
> [...snip...] 
> You can also do initialisation after all the properties have been set. 
> See the FAQ entry "How do I know when a managed bean's properties have 
> all been set?".
There's a method called initDao() in the class 
org.springframework.jdbc.core.support.JdbcDaoSupport which should be 
overwritten in a case you need to init a DAO (which is the case in my 
situation).
But this one is not called by JSF right? So I'd need to use spring to 
construct the bean?

Thank you for pointing to the FAQ - missed that one ..

Take care, Kurt
> 
> http://wiki.apache.org/myfaces/FAQ
> 
>> Or is possible to use/reference Spring beans in faces-config.xml?
> 
> 
> Any managed-property like:
>   <managed-property>
>     <name>foo</name>
>     <value>#{someValue}</value>
>   </managed-property>
> simply looks for a key "someValue" in the request, session and 
> application scopes. So if your spring bean is stored in one of those 
> maps then it will be passed to the managed bean on creation.
> 
> 
> Regards,
> 
> Simon


Re: Bean definition question faces-config.xml

Posted by Simon Kitching <sk...@obsidium.com>.
Kurt Edegger wrote:
> Hi,
> 
> I wonder if it is possible to declare the constructor of a bean in 
> faces-config.xml similar to using <constructor-arg> in spring's 
> configuration files.

This is definitely not a feature of the JSF specification, and MyFaces 
can't add any new tags to the faces-config.xml file without violating 
the spec.

> The idea behind this is, that I'd like to inject a bean into my 
> application and use a referenced bean already in the constructor.
> As far as I know and encountered, first the default constructor is 
> called, then the referenced beans are injected by using the 
> corresponding setters, and finally the bean is used in the application 
> depending of the scope.

There's no way to set anything in the constructor AFAIK.

The constructor could manually look up the desired object, though: see 
the FAQ entry "How can I access one Managed Bean from another?".

You can also do initialisation after all the properties have been set. 
See the FAQ entry "How do I know when a managed bean's properties have 
all been set?".

http://wiki.apache.org/myfaces/FAQ

> Or is possible to use/reference Spring beans in faces-config.xml?

Any managed-property like:
   <managed-property>
     <name>foo</name>
     <value>#{someValue}</value>
   </managed-property>
simply looks for a key "someValue" in the request, session and 
application scopes. So if your spring bean is stored in one of those 
maps then it will be passed to the managed bean on creation.


Regards,

Simon

Re: Bean definition question faces-config.xml

Posted by Aleksei Valikov <va...@disy.net>.
Hi.

> I wonder if it is possible to declare the constructor of a bean in 
> faces-config.xml similar to using <constructor-arg> in spring's 
> configuration files.
> The idea behind this is, that I'd like to inject a bean into my 
> application and use a referenced bean already in the constructor.
> As far as I know and encountered, first the default constructor is 
> called, then the referenced beans are injected by using the 
> corresponding setters, and finally the bean is used in the application 
> depending of the scope.
> Or is possible to use/reference Spring beans in faces-config.xml?

Of course you can use/reference Spring beans in faces-config.xml. Just 
use Spring's variable resolver.

<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>

If you want to declare your bean in Spring context but make it available 
as a managed bean (for instance, to define bean scoping), use proxies.

Bye.
/lexi