Could you elaborate on this? Shawn
-----Original Message----- From: news [mailto:[EMAIL PROTECTED] On Behalf Of Laurie Harper Sent: Wednesday, January 04, 2006 5:38 PM To: user@struts.apache.org Subject: Re: [Shale/JSF] Craig McClanahan wrote: > On 1/4/06, Garner, Shawn <[EMAIL PROTECTED]> wrote: >> How do you get access to one managed bean from within another managed >> bean? >> >> We have some business logic that depends on values in another managed. > > > If you're trying to gain access from a class that extends AbstractFacesBean > or AbstractViewController, this is really simple: > > MyBean bean = (MyBean) getBean("name"); // "name" == managed bean name > of the other bean > > If you are in a class that doesn't extend one of these, it's a little more > work but still straightforward: > > FacesContext context = FacesContext.getCurrentInstance(); > ValueBinding vb = context.getApplication().createValueBinding("#{name}"); > MyBean bean = (MyBean) vb.getValue(context); > > Either of the above techniques will cause the other managed bean to be > created, if it doesn't exist. If you *know* it exists, and what scope it is > in, you can also use the appropriate scoped map. Assume the other bean is > in session scope: > > FacesContext context = FacesContext.getCurrentInstance(); > MyBean bean = (MyBean) context.getExternalContext > ().getSessionMap().get("name"); > > Shawn > > > Craig It's probably also worth pointing out that you could use 'dependency injection' -- i.e. a managed property -- to supply the dependent bean with its dependency, declaratively, through the faces-config.xml. L. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] **************************************************************************** This email may contain confidential material. If you were not an intended recipient, Please notify the sender and delete all copies. We may monitor email to and from our network. **************************************************************************** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]