By: HenryAlthough 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.
Most Viewed Articles (in JSF )
Latest Articles (in JSF)
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Subscribe to Tutorials
1. Is so easy work with FacesContext. For me, the get
View Tutorial By: Fred at 2009-03-11 08:42:59