Hi,
I have never used the faces-config.xml injection. I used to initialize
anything in my bean constructors,
until I understood this is a bad thing to do... (at least for fetching data
from all sort of services...).
So currently this is what I am doing to initialize data:
private someData;
public List getSomeData()
{
If (someData == null)
{
someData = myService.getData();
}
return someData;
}
In addition, if you want to pass a parameter to this page (it usually one
parameter, something like object id).
I simply use the regular query string mechanism for that. So all you have to
do is get the parameter from the request and initialize data using that
parameter (note that passing parameters in this method has not much of
support by core JSF).
If you want to further investigate, I am currently using in one of my
projects Seam framework, which is a great thing.
It has built-in facilities for initializing data and using request
parameters.
-----Original Message-----
From: Simon Kitching [mailto:[EMAIL PROTECTED]
Sent: Wednesday, August 20, 2008 2:47 PM
To: MyFaces Discussion
Subject: Re: Composite view from several "request" managed beans
Anton Gavazuk schrieb:
>
>>> All necessary beans will be instantiated automatically by JSF as long as
you
>>> define them in your faces-config.xml file.
>>>
> its clear,
> but I want to put some business related info in bean before showing them.
> like following
> JSF method {
> SomeBean = new SomeBean();
> SomeBean.value1 = Service.getSomething();
> SomeBean.value2 = Service.getSomething();
>
> SomeBean2 = new SomeBean2();
> .....
> //now I can add these beans to faces context of course, but maybe
> there is another way?
> }
>
> I dont want to call business functions inside getters of managed beans.
>
If any class should be initialised before use, then the normal place to
do that is in the class constructor.
If you need to have some values injected into your bean first, then
unfortunately the constructor cannot be used as faces-config.xml does
not support injecting of constructor-args. In that case, you can:
* use a better dependency-injection framework like Spring (spring can be
used with JSF)
* use the @PostConstruct annotation to mark some method that should be
called after injection is complete
(but unfortunately there is a bug in myFaces that means this doesn't
currently work)
* rely on the fact that injection always occurs in the order listed in
the faces-config.xml file.
Regards,
Simon