This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes JSF and the fly likes Using FacesCcntext within Listeners and Filters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Using FacesCcntext within Listeners and Filters" Watch "Using FacesCcntext within Listeners and Filters" New topic
Author

Using FacesCcntext within Listeners and Filters

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Is it okay to use FacesContext within Listeners or filters in order to retrieve the Http Request Object?
Tom Fulton
Ranch Hand

Joined: Mar 30, 2006
Posts: 95
In the case of a listener (Action- or ValueChange), the answer is yes...FacesContext can be accessed by calling the static getCurrentInstance method: FacesContext.getCurrentInstance(). FacesContext essentially represents the request as it travels through the JSF lifecycle.

I am guessing (but I'm not sure) that the same does not apply to filters. Although the request itself is available, FacesServlet may not have instantiated FaceContext yet. But you can get at the HttpRequest object in the filter, because it is a parameter passed into the doFilter method (OK, it's passed as a ServletRequest, but can be cast, if I'm not mistaken).
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I know it can be accessed but the question is is it appropriate to obtain the request object in a (Listener/Filter) using a FacesContext
 
Consider Paul's rocket mass heater.
 
subject: Using FacesCcntext within Listeners and Filters