You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Carlos Ortiz <co...@coral-technologies.com> on 2007/05/18 19:52:27 UTC
How To use Values from a bean in a other
Hi
How To use Values from a bean in a other
I'll to do this.
I Have my Bean A
then i like to put the arrtibute xx in a bean B
example
use the iduser attribute form a session bean in a request bean for a
simple search ,
the request bean has a attribute iduser. but how do i set it to request
iduser = session iduser,
i also need that for request to request bean.
thx
Re: How To use Values from a bean in a other
Posted by Andrew Robinson <an...@gmail.com>.
On 5/18/07, Carlos Ortiz <co...@coral-technologies.com> wrote:
> Thx Just a couple questions.
>
> > Multiple ways
> >
> > 1) Use JBoss-Seam @In/@Out annotations to inject/outject the values
> > 2) Use managed properties in the faces-config.xml to have bean b
> > always pull the value from bean A for a given property
> Noob , How i do that ?¡
<managed-bean>
<managed-bean-name>A</managed-bean-name>
<managed-bean-class>example.A</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>B</managed-bean-name>
<managed-bean-class>example.B</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>valueFromA</property-name>
<value>#{A.propertyFromA}</value>
</managed-property>
</managed-bean>
This assumes A has "getPropertyFromA" and B has "setValueFromA", so
just change those property names to fit your use case
> > 3) Put the value in the ExternalContext requestMap in bean A and get
> > it in bean B from the same map
> > 4) Set it directly:
> >
> > FacesContext facesContext = FacesContext.getCurrentInstance();
> > ValueBinding vb =
> > facesContext.getApplication().createValueBinding("#{B}");
> > B b = (B)vb.getValue(facesContext);
> > b.setPropValue(getPropValue());
> Does this last one works for all type of beans (request,session
> application ...) ¡?
Yes, because the faces context (application actually) already knows
the scope of every bean due to its declared scope in the
faces-context. If the bean doesn't already exist, it is created and
stored in the scope defined from the configuration file.
Re: How To use Values from a bean in a other
Posted by Carlos Ortiz <co...@coral-technologies.com>.
Thx Just a couple questions.
> Multiple ways
>
> 1) Use JBoss-Seam @In/@Out annotations to inject/outject the values
> 2) Use managed properties in the faces-config.xml to have bean b
> always pull the value from bean A for a given property
Noob , How i do that ?¡
> 3) Put the value in the ExternalContext requestMap in bean A and get
> it in bean B from the same map
> 4) Set it directly:
>
> FacesContext facesContext = FacesContext.getCurrentInstance();
> ValueBinding vb =
> facesContext.getApplication().createValueBinding("#{B}");
> B b = (B)vb.getValue(facesContext);
> b.setPropValue(getPropValue());
Does this last one works for all type of beans (request,session
application ...) ¡?
>
> Do any of those match what you are looking for?
>
> On 5/18/07, Carlos Ortiz <co...@coral-technologies.com> wrote:
>> Hi
>> How To use Values from a bean in a other
>> I'll to do this.
>>
>> I Have my Bean A
>> then i like to put the arrtibute xx in a bean B
>>
>> example
>> use the iduser attribute form a session bean in a request bean for a
>> simple search ,
>> the request bean has a attribute iduser. but how do i set it to request
>> iduser = session iduser,
>> i also need that for request to request bean.
>>
>> thx
>>
>>
Re: How To use Values from a bean in a other
Posted by Andrew Robinson <an...@gmail.com>.
Multiple ways
1) Use JBoss-Seam @In/@Out annotations to inject/outject the values
2) Use managed properties in the faces-config.xml to have bean b
always pull the value from bean A for a given property
3) Put the value in the ExternalContext requestMap in bean A and get
it in bean B from the same map
4) Set it directly:
FacesContext facesContext = FacesContext.getCurrentInstance();
ValueBinding vb = facesContext.getApplication().createValueBinding("#{B}");
B b = (B)vb.getValue(facesContext);
b.setPropValue(getPropValue());
Do any of those match what you are looking for?
On 5/18/07, Carlos Ortiz <co...@coral-technologies.com> wrote:
> Hi
> How To use Values from a bean in a other
> I'll to do this.
>
> I Have my Bean A
> then i like to put the arrtibute xx in a bean B
>
> example
> use the iduser attribute form a session bean in a request bean for a
> simple search ,
> the request bean has a attribute iduser. but how do i set it to request
> iduser = session iduser,
> i also need that for request to request bean.
>
> thx
>
>