The code below works for accessing bean instances from other beans (as long as 
they exist)...

/**
 * Gets a managed bean from the current context using the specified bean
 * class/name. This is useful when attempting to extract a subview bean.
 * The <code>beanName</code> represents the name of the bean instance 
 * designated in <code>faces-config.xml</code> managed bean.
 * 
 * @param beanClass
 * @param beanName
 */
@SuppressWarnings("unchecked")
public static final <T extends Object> T getManagedBean(
                Class<? super T> beanClass, String beanName) {
        FacesContext context = FacesUtil.getFacesContext();
        return (T) context.getApplication().getVariableResolver()
                        .resolveVariable(context, beanName);
}

-----Original Message-----
From: Thai Dang Vu [mailto:[EMAIL PROTECTED]
Sent: Thursday, July 26, 2007 10:44 AM
To: MyFaces Discussion
Subject: RE: Instantiate a backing bean from other


What do you mean about "Use spring, forget about faces managed-beans"? Do you 
have a way to use a Spring bean as a JSF managed bean (declare that bean in a 
xml file, not in faces-config.xml)?

-----Original Message-----
From: Michał 'Gandalf' Stawicki [mailto:[EMAIL PROTECTED] 
Sent: Thursday, July 26, 2007 10:40 AM
To: MyFaces Discussion
Subject: Re: Instantiate a backing bean from other

Use spring, forget about faces managed-beans ;)

On 26/07/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
> Hello,
>
> It depends on the use case:
>
> 1. If the bean needing the information for the other is request scoped, the
> info is always needed and is unlikely to change over the request lifecycle,
> using a managed-property to inject the value directly is most likely the
> best way.
> 2. If the required value change over the request lifecycle or the bean is
> more persistent than request and the requested value change over time, then
> use a managed-property to inject the other bean itself.
> 3. Use the VariableResolver, it's more efficient than ValueBinding.
>
>
> Regards,
>
> ~ Simon
>
>
> On 7/26/07, Fabio Stracuzzi <[EMAIL PROTECTED]> wrote:
> >
> > FacesContext currentFacesContextInstance =
> FacesContext.getCurrentInstance();
> > You can test this code:
> >
> > ValueBinding valueBinding =
> currentFacesContextInstance.getApplication().createValueBinding("#{"
> + managedBeanName + "}");
> >
> > return valueBinding.getValue(currentFacesContextInstance);
> >
> > If Your managedBean has Session scope (or Application Scope), the returned
> bean is same istance, otherwise the method will create a new instance.
> >
> > Best regarde
> > Fabio
> >
> >
> > 2007/7/26, Angel Miralles Arevalo <[EMAIL PROTECTED]>:
> >
> > >
> > >
> > >
> > > It isn't necesary managed bean in session scope, for example:
> > >
> > >
> > >
> > > AuthorizationMembersGroupBean menGroup = (AuthorizationMembersGroupBean)
> getApplication().createValueBinding("#{requestScope.authorizationMembersGroupBean}"
> ).getValue(facesContext);
> > >
> > >
> > >
> > >
> > >
> > >
> getApplication().createValueBinding("#{requestScope.authorizationMembersGroupBean}").setValue(facesContext,menGroup);
> > >
> > >
> > > What you need to know is than you obtain the managed bean, alter it and
> you have to update it in facesContext...the second line...
> > >
> > > ----- Mensaje original ----
> > > De: daniel ccss < [EMAIL PROTECTED]>
> > > Para: MyFaces Discussion <[email protected]>
> > > Enviado: jueves, 26 de julio, 2007 15:56:25
> > > Asunto: Instantiate a backing bean from other
> > >
> > >
> > > Is there a way to use a BackingBean from another BackingBean o another
> class, the scope of the backing bean is session.
> > >
> > > For example I need to call the get method of a variable of a BackingBean
> on another Backing Bean
> > >
> > > It is possible or I´m to crazy?
> > >
> > >
> > > ________________________________
>
> > > Sé un Mejor Amante del Cine
> > > ¿Quieres saber cómo? ¡Deja que otras personas te ayuden! .
> > >
> >
> >
> >
> > --
> > Ciao ciao
> > Fabio
>
>


-- 
Michał Stawicki

[EMAIL PROTECTED]
http://stawicki.jasliska.pl



NOTICE: This message (including any attachments) from Momentum Systems, Inc. 
contains information that is PRIVILEGED and CONFIDENTIAL.  If you are not an 
intended recipient, you are hereby notified that any dissemination of this 
message is strictly prohibited.  If you have received this message in error, 
please do not read, copy or forward this message.  Please permanently delete 
all copies and any attachments and notify the sender immediately by reply email 
or by calling our Office at 703.740.9300.

Reply via email to