aspose file tools
The moose likes JSF and the fly likes Obtaining an instance of a Managed Bean declared with Application Level Scope Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Obtaining an instance of a Managed Bean declared with Application Level Scope" Watch "Obtaining an instance of a Managed Bean declared with Application Level Scope" New topic
Author

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

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
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
Ryan Lubke
Ranch Hand

Joined: Jun 20, 2007
Posts: 36
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

Joined: Jan 17, 2002
Posts: 495
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Obtaining an instance of a Managed Bean declared with Application Level Scope
 
Similar Threads
Equivalent of servlet init() in JSF
JSF Backing bean in session Scope and State_Saving_Method = Client
managing Faces-config in jSF ...please explain.
managed bean injection problem
Face managed bean in RAD7