On Sat, 2007-09-08 at 15:01 +0200, [EMAIL PROTECTED] wrote:
> I am thinking about a way on how to transfer data objects across
> several managed-beans. Say I have two wizard pages, each having
> managed beans as their "controller". Now both want to modify a DTO
> that comes from the business layer. Now how do you pass the modified
> DTO from the first backing bean to the second?
>
> Using managed properties my first approach was to inject
> #{firstBean.dto} into #{secondBean.dto}. However, this creates a
> dependency on the order (what if page 2 becomes page 1?). I would like
> to inject #{dto} only. So, this raises the question: Why not make the
> DTO become a managed bean? Are there any disadvantages? I have not
> seen this approach in any JSF tutorials.
EL expressions don't just reference managed beans, they reference any
accessable object, eg objects in session scope. And "managed beans" do
not have to just be backing beans (ie code referenced directly from EL
expressions in the view).
It sounds from your example like the DTO really does have a different
lifetime from the two backing beans that use it. So why not just put
this DTO directly into the session under some known name when it is
created, and inject this object into both backing beans?
Alternatively, define a "manager" type object for your DTO as a managed
bean, and inject this manager into both your pages.
> What if the DTO becomes a, say hibernate, entity. Will the JSF
> lifecycle methods make this impossible?
If the object is read-only then there's not much difference from a
non-hibernate entity (except the risk of LazyInitializationException
when accessing uninitialised relations). However for other operations
you're obviously going to have difficulties as the
JPA/hibernate/whatever session is closed at the end of each request (at
least).
You might want to have a look at the MyFaces Orchestra project. Note
that Orchestra is still very new (hopefully its very first release is
coming in the next week or so) but it is intended to deal with the issue
of "wizard" type view sequences ("conversations"), and also dealing with
persistent objects in such sequences.
Regards,
Simon