You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Mike Duffy <md...@yahoo.com> on 2006/02/14 09:19:59 UTC

How to access one managed-bean from another managed-bean?

This is a good FAQ:

http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+access+one+managed-bean+from+another+managed-bean%3F&page=HowToAccessOneManagedBeanFromAnotherManagedBean

However, the solutions seem to require that both beans be in session scope.

Let's say I have a form page that leads to another form page and I want the values from the first
backing bean to available in the second backing bean AND I want to keep both backing beans in
request scope (I just hate trashing up the sessions).

Any suggestions on how to do this?

Thx.

Mike

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Re: How to access one managed-bean from another managed-bean?

Posted by Craig McClanahan <cr...@apache.org>.
On 2/14/06, Dave Brondsema <da...@brondsema.net> wrote:
>
> Use their 3rd solution (<managed-property>).


That would be my general recommendation at well.

For any of the solutions they discuss, beans can be in any scope.  They
> just used 'session' as an example.


But, this needs to be clarified a bit.  You cannot inject a reference from a
"shorter" lived bean into a "longer" lived bean (indeed, the JSF
implementation catches that; MyFaces certainly caught me on it when I tried
by accident :-).

For example, it's OK for a request-scoped bean to reference a session-scoped
bean, but not the other way around.  It's also OK to reference a
session-scoped bean from another session scoped bean.

Craig

Re: How to access one managed-bean from another managed-bean?

Posted by Dudu <ed...@yahoo.com.br>.
An Example.

        FacesContext fc = FacesContext.getCurrentInstance();
        ValueBinding vb = fc.getApplication
().createValueBinding("#{usuario}");
        Usuario usr = (Usuario)vb.getValue(fc); //get the managed bean
        usr.operations();
        vb.setValue(fc,usr)  //set the managed bean

On 2/14/06, Dave Brondsema <da...@brondsema.net> wrote:
>
> Use their 3rd solution (<managed-property>).
>
> For any of the solutions they discuss, beans can be in any scope.  They
> just used 'session' as an example.
>
> Mike Duffy wrote:
> > This is a good FAQ:
> >
> >
> http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+access+one+managed-bean+from+another+managed-bean%3F&page=HowToAccessOneManagedBeanFromAnotherManagedBean
> >
> > However, the solutions seem to require that both beans be in session
> scope.
> >
> > Let's say I have a form page that leads to another form page and I want
> the values from the first
> > backing bean to available in the second backing bean AND I want to keep
> both backing beans in
> > request scope (I just hate trashing up the sessions).
> >
> > Any suggestions on how to do this?
> >
> > Thx.
> >
> > Mike
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
>
>
> --
> Dave Brondsema
> Software Developer
> Cornerstone University
>
>
>
>


--
Dudu
----------
GoogleTalk: eduardopichler@gmail.com
skype:eduardopichler

Re: How to access one managed-bean from another managed-bean?

Posted by Dave Brondsema <da...@brondsema.net>.
Use their 3rd solution (<managed-property>).

For any of the solutions they discuss, beans can be in any scope.  They
just used 'session' as an example.

Mike Duffy wrote:
> This is a good FAQ:
> 
> http://www.jsffaq.com/Wiki.jsp?ptitle=How+to+access+one+managed-bean+from+another+managed-bean%3F&page=HowToAccessOneManagedBeanFromAnotherManagedBean
> 
> However, the solutions seem to require that both beans be in session scope.
> 
> Let's say I have a form page that leads to another form page and I want the values from the first
> backing bean to available in the second backing bean AND I want to keep both backing beans in
> request scope (I just hate trashing up the sessions).
> 
> Any suggestions on how to do this?
> 
> Thx.
> 
> Mike
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> 


-- 
Dave Brondsema
Software Developer
Cornerstone University