Werner Punz wrote:
QueryHelper qh = new QueryHelper(); ---> HERE I'm making a new Object
of the second bean!!! The methods of the object qh fill some
SelectItem[] Variables...
this is your problem, you should use the jsf variable resolver mechanism
to take care of the backend bean generation.
I can recommend to use the excellent JsfUtil class you can find
on www.javaworld.com and in appfuse, which encapsules all the
mechanisms. This class has a getManagedBean method which takes care
of all that.
I think the "getManagedBean" method is looking at the problem the wrong
way. The server world is definitely moving towards "dependency
injection" as a replacement for "dependency lookup". Examples are
Spring, HiveMind, EJB3.
JSF supports "dependency injection" in the managed bean declarations:
<managed-bean>
<managed-bean-name>queryHelper</managed-bean-name>
<managed-bean-class>example.QueryHelper</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>foo</managed-bean-name>
<managed-bean-class>example.Foo</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<!-- use dependency injection to pass queryHelper -->
<managed-property>
<property-name>queryHelper</property-name>
<value>#{queryHelper}</value>
</managed-property>
</managed-bean>
This will cause Foo.setQueryHelper(obj) to be called when a "managed
bean" instance of Foo is created, passing the queryHelper managed bean
instance as a parameter.
No need to "look up" the bean at all; it gets effectively passed as an
"initialisation value" to the Foo object.
NB: the lookup implemented by the JsfUtils lib will work, and there's
nothing wrong with it. It just seems a little "old fashioned" now.
NB2: Someone did report difficulties getting this approach working with
JSF on Spring.
Regards,
Simon