You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Dennis Byrne <de...@dbyrne.net> on 2006/06/01 22:35:10 UTC

[OT] scope trick

The spec says higher scoped managed beans cannot be injected into lower scoped managed beans.  This doesn't mean we can't inject session scoped data into request scope managed beans ...

<managed-bean>
 <managed-bean-name>geographyProducer</managed-bean-name>
 <managed-bean-class>gov.blm.ak.GeographyConsumerThread</managed-bean-class>
 <managed-bean-scope>request</managed-bean-scope>   
  <managed-property>
    <property-name>sharedData</property-name>
    <value>#{facesContext.externalContext.sessionMap['sharedData']}</value>
  </managed-property>
</managed-bean>

Dennis Byrne



Re: [OT] scope trick

Posted by Craig McClanahan <cr...@apache.org>.
On 6/1/06, Dennis Byrne <de...@dbyrne.net> wrote:
>
> The spec says higher scoped managed beans cannot be injected into lower
> scoped managed beans.  This doesn't mean we can't inject session scoped data
> into request scope managed beans ...
>
> <managed-bean>
> <managed-bean-name>geographyProducer</managed-bean-name>
> <managed-bean-class>gov.blm.ak.GeographyConsumerThread
> </managed-bean-class>
> <managed-bean-scope>request</managed-bean-scope>
>   <managed-property>
>     <property-name>sharedData</property-name>
>     <value>#{facesContext.externalContext.sessionMap
> ['sharedData']}</value>
>   </managed-property>
> </managed-bean>


I had to read your double negative three times before I think I got it :-)

Yes, you can do this ... but you are working too hard with that kind of an
expression.  Try this instead:

    <value>#{sharedData}</value>

As long as you don't also have a "sharedData" bean in request scope, this
will pick up the session scoped bean for you (and also create it if
necessary, if it is a managed bean).

Dennis Byrne


Craig

Re: [OT] scope trick

Posted by Ondrej Svetlik <on...@svetlik.info>.
Dennis Byrne wrote:
> The spec says higher scoped managed beans cannot be injected into lower scoped managed beans.  This doesn't mean we can't inject session scoped data into request scope managed beans ...
> 
> <managed-bean>
>  <managed-bean-name>geographyProducer</managed-bean-name>
>  <managed-bean-class>gov.blm.ak.GeographyConsumerThread</managed-bean-class>
>  <managed-bean-scope>request</managed-bean-scope>   
>   <managed-property>
>     <property-name>sharedData</property-name>
>     <value>#{facesContext.externalContext.sessionMap['sharedData']}</value>
>   </managed-property>
> </managed-bean>
> 
> Dennis Byrne
> 

Well, in my opinion, this is exactly what the spec says.

http://wiki.apache.org/myfaces/AccessingOneManagedBeanFromAnother

<cite>
The constraints are that:

  * the using bean must have scope which is the same as or shorter than 
the needed bean
  * the using bean must have a property-setter method which takes the 
needed bean as a parameter
  * the beans cannot have managed dependencies on each other.
</cite>

In your example geographyProducer is the using bean and has shorter 
scope (request) than the session scoped bean, whatever way you use to 
access it.

Best regards

Ondrej Svetlik