Accessing Context Data in Beans using JSF

By: Henry Emailed: 1745 times Printed: 2431 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

Although JSF makes it easy for you to connect the view with the model without writing any code, at times you may need direct access to the request data or other data of your web application. 

JSF provides access to the request data and other data through the FacesContext object. As the Javadoc states, “FacesContext contains all of the per-request state information related to the processing of a single JavaServer Faces request, and the rendering of the corresponding response . . . . A FacesContext instance is associated with a particular request at the beginning of request processing.” Because a FacesContext instance, and the objects it contains, are associated with the thread processing a particular request, any references to the FacesContext instance or its contained objects must not be passed to another thread or stored for subsequent requests.

You can access the FacesContext object like this:

FacesContext context = FacesContext.getCurrentInstance();

After you have a reference to the FacesContext for the request, you can access all the request and application data through the ExternalContext object. The reference to the ExternalContext object is obtained through the call to the getExternalContext() method. Table below shows the methods of ExternalContext that return collections of request and application data. You can use these methods to access request data, session data, request header data, cookie data, and other sets of data in the application.



Most likely, if you are accessing request or application data in a managed bean, you will be accessing request data or session data. As you can see in Table, you access request data through the getRequestParameterMap() or getRequestParameterValuesMap() method. You can access session data through the getSessionMap() method.


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(1)


1. View Comment

Is so easy work with FacesContext. For me, the getSessionMap method is an big guy that help me work everyday. =D

_o/


View Tutorial          By: Fred at 2009-03-11 08:42:59

Your name (required):


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


Your sites URL (optional):


Your comments:



More Tutorials by Henry
Generating Your Key Pair example using keytool in Java
Summary of Operators in Java
JDBC Basics and JDBC Components
The IterationTag Interface in JSP
Trigonometric, Hyperbolic, Exponential and Logarithmic Functions in C
Using Bit-field in C
Java Beans and the Expression Language
Initialization of Variables in C
Creating Struts Modules
else if statement in C
Line Counting sample program in C
Accessing Context Data in Beans using JSF
Using peek() and putback() with cin in C++
Internationalization Support in J2ME MIDP
java.lang.SecurityException: MIDP lifecycle does not support system exit.

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