You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Ole Ersoy <ol...@gmail.com> on 2008/01/04 05:13:25 UTC

Getting the backing bean via a phase listener

Hi,

I'd like to have a phase listener that retrieves the backing bean updated during a post.  Is there a handle exposing it generically (Type Object) somewhere...?

TIA,
- Ole




Re: Getting the backing bean via a phase listener

Posted by Ole Ersoy <ol...@gmail.com>.
Hi Simon,

The scenario I have in mind is:
- Backing bean(s) get(s) updated via ajax request
- A handle to the backing bean(s) is obtained
- An SDO Data Access Service (DAS) processes the backing bean(s)

The phase listener would find the backing bean or beans and set their properties using reflection, thus avoiding explicitly binding each form EditableValue to a property of the bean (The assumption is that the field names match the bean property names).

I think lookup method (Provided in the link you gave me for looking up an arbitrary bean) will work.  Then I'd just have to get the bean name(s) into the form using a hidden field, and send it as a header in the post request.  I'll probably just make a custom form component for this.  I'll be glad to contribute it if there's interest.  Super - I'll give this a shot.

Thank you very much for the link.  

Cheers,
- Ole




simon wrote:
> On Thu, 2008-01-03 at 22:13 -0600, Ole Ersoy wrote:
>> Hi,
>>
>> I'd like to have a phase listener that retrieves the backing bean updated during a post.  Is there a handle exposing it generically (Type Object) somewhere...?
> 
> There is no concept of "the" backing bean for a view in JSF. A view can
> have many associated beans, or none.
> 
> You can access an arbitrary bean by name using the "looup" techniques
> described here:
> http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother
> 
> However the problem remains of deciding what bean name to retrieve.
> There isn't any standard answer for that. Depending on *why* you want to
> do this, the Apache Shale view controller framework might be worth
> looking at; it looks for a managed bean with a name that "matches" the
> viewId. The MyFaces Orchestra view controller does something similar.
> 
> Regards,
> 
> Simon
> 
> 

Re: Getting the backing bean via a phase listener

Posted by simon <si...@chello.at>.
On Thu, 2008-01-03 at 22:13 -0600, Ole Ersoy wrote:
> Hi,
> 
> I'd like to have a phase listener that retrieves the backing bean updated during a post.  Is there a handle exposing it generically (Type Object) somewhere...?

There is no concept of "the" backing bean for a view in JSF. A view can
have many associated beans, or none.

You can access an arbitrary bean by name using the "looup" techniques
described here:
http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother

However the problem remains of deciding what bean name to retrieve.
There isn't any standard answer for that. Depending on *why* you want to
do this, the Apache Shale view controller framework might be worth
looking at; it looks for a managed bean with a name that "matches" the
viewId. The MyFaces Orchestra view controller does something similar.

Regards,

Simon