Java Bean Scopes in JSF

By: Ivan Lim Emailed: 1609 times Printed: 2079 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

When you configure a JavaBean to be used in a JSF page, you can configure it with one of four
scopes:

None: Objects with this scope are not visible in any JSF page. When used in the configuration file, they indicate managed beans that are used by other managed beans in the application. Objects with none scope can use other objects with none scope.

Request: Objects with this scope are visible from the start of the request until the end
of the request. Request scope starts at the beginning of a request and ends when the
response has been sent to the client. If the request is forwarded, the objects are visible
in the forwarded page, because that page is still part of the same request/response
cycle. Objects with request scope can use other objects with none, request, session,
or application scope.

Session: An object with session scope is visible for any request/response cycle that
belongs to a session. Objects with this scope have their state persisted between
requests and last until the object or the session is invalidated. Objects with session
scope can use other objects with none, session, or application scope.

Application: An object with application scope is visible in all request/response cycles
for all clients using the application, for as long as the application is active. Objects with
application scope can use other objects with none or application scope.

You may know that when you use the <useBean> standard action, you can specify similar scopes for the JavaBean. The difference is that JSP scope includes an additional scope named page. Because JSF requests often involve navigation between pages, objects with page scope have no value in a JSF application.

Most often, you will define your managed beans to have session scope. However, in some cases, you may have a managed bean that encapsulates global data. For example, you may have a managed bean that holds information common to every page in the application; in that case, you would define the managed bean to have application scope. Managed beans that you use only within a single request/response will have request scope.


JSF Home | All JSF Tutorials | Latest JSF Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(6)


1. View Comment

thanks. that was fair enough. :)

View Tutorial          By: Mustafa at 2010-05-16 10:12:33
2. View Comment

Thanks. Well explanation..

View Tutorial          By: Ebi Divakar at 2011-07-26 04:31:30
3. View Comment

Thank uvery much :) u r so helpful

View Tutorial          By: Ahmed at 2011-12-04 10:01:11
4. View Comment

tnx man that was short and well explained...

View Tutorial          By: jsf noob at 2012-02-02 13:24:12
5. View Comment

What about object bean with view scope?

View Tutorial          By: Awo at 2012-02-11 12:17:36
6. View Comment

what about object bean with view scope ??

View Tutorial          By: abdelaziz akharraz at 2012-10-09 15:06:52

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Ivan Lim
Requesting a Signed Certificate from a Certification Authority example using keytool in Java
The if-then Statement in Java
SELECT Statements
The BodyTag Interface in JSP
Handling Duplicate Form Submissions in Struts
Standard Input and Output in C
A sample that shows Java Beans, Servlets and JSP working together
Recursion in C
Using Multibox in Struts
switch in C
Word Counting sample program in C
Java Bean Scopes in JSF
Using cout.width() in C++
Types of configurations in J2ME
How to get the CLDC and MIDP version from a J2ME program

More Tutorials in JSF
Struts Vs JSF (A comparison of Struts against JSF)
faces-config.xml to DirectTraffic in the JSF Application
<convertNumber> and <convertDateTime> in JSF
Action listeners in JSF
Calling Multiple Listeners in JSF
Using Javascript in JSF
How to open a new browser window from my JSF page?
Servlet error : java.lang.IndexOutOfBoundsException (JSF RI 1.1_01: IndexOutOfBoundsException)
JSF - TreeNode.setID gets IllegalArgument Exception
Install and Deploy JBoss Application Server
What is JSF (JavaServer Faces)?
Differences between JavaServer Faces technology and Struts
JSF Basics
The Relationship Between JSF and Other Java EE Technologies
JSF Life Cycle

More Latest News
Most Viewed Articles (in JSF )
Java Bean Scopes in JSF
Using Javascript in JSF
JSF Life Cycle
<convertNumber> and <convertDateTime> in JSF
Action listeners in JSF
Install and Deploy JBoss Application Server
Controlling Page Navigation in JSF - Static and Dynamic Navigation
What is JSF (JavaServer Faces)?
The Relationship Between JSF and Other Java EE Technologies
Installing JSF
Accessing Context Data in Beans using JSF
How to open a new browser window from my JSF page?
JSF - TreeNode.setID gets IllegalArgument Exception
Struts Vs JSF (A comparison of Struts against JSF)
Differences between JavaServer Faces technology and Struts
Most Emailed Articles (in JSF)
Accessing Context Data in Beans using JSF
What is JSF (JavaServer Faces)?
Servlet error : java.lang.IndexOutOfBoundsException (JSF RI 1.1_01: IndexOutOfBoundsException)
Action listeners in JSF
Calling Multiple Listeners in JSF
Install and Deploy JBoss Application Server
JSF Life Cycle
Java Bean Scopes in JSF
JSF Basics
Installing JSF
Controlling Page Navigation in JSF - Static and Dynamic Navigation
<convertNumber> and <convertDateTime> in JSF
How to open a new browser window from my JSF page?
JSF - TreeNode.setID gets IllegalArgument Exception
faces-config.xml to DirectTraffic in the JSF Application