• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Obtaining an instance of a Managed Bean declared with Application Level Scope

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a managed bean that i have defined with Application Level Scope that means it only gets instantiated once during the life
of the application, Now i would like to get a reference to that instance from my Managed bean which has Session Level Scope, Please how do i go about this, and i would not want to say A ab=new A(); as this would create another instance
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Abiodun Adisa:
I have a managed bean that i have defined with Application Level Scope that means it only gets instantiated once during the life
of the application, Now i would like to get a reference to that instance from my Managed bean which has Session Level Scope, Please how do i go about this, and i would not want to say A ab=new A(); as this would create another instance



Say your application scoped managed bean is called 'app'.

Then in your session managed bean definition you'd:



When 'sessBean' is instaniated by JSF, the application scoped bean will
be injected into the instance. You need to make sure there is public property accessors for this to work of course.
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ryan Lubke:


Say your application scoped managed bean is called 'app'.

Then in your session managed bean definition you'd:



When 'sessBean' is instaniated by JSF, the application scoped bean will
be injected into the instance. You need to make sure there is public property accessors for this to work of course.




Hello,
I did it as you suggested but it did'nt work, I am posting my code probably i missed something

Faces-Config.xml

<faces-config xmlns="http://java.sun.com/JSF/Configuration">
<managed-bean>
<managed-bean-name>backing_index</managed-bean-name>
<managed-bean-class>view.backing.Index</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>Test</property-name>
<value>#{Testing}</value>
</managed-property>
</managed-bean>

<managed-bean>
<managed-bean-name>backing_content</managed-bean-name>
<managed-bean-class>view.backing.Content</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/content.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>Testing</managed-bean-name>
<managed-bean-class>view.backing.Testing</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
</managed-bean>
</faces-config>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
and for the accessors

public void setTest(Testing test) {
this.Test = test;
//System.out.println("Session Bean Injectd with Test"+Test.result);
}

public Testing getTest() {
return Test;
}

but then i kept getting this error

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.FacesException: Can't set managed bean property: 'Test'.at com.sun.faces.taglib.html_basic.FormTag.doStartTag(FormTag.java:355)at _index._jspService(_index.java:60)[/index.jsp
 
reply
    Bookmark Topic Watch Topic
  • New Topic