myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Kienenberger" <>
Subject Re: How to get the FacesContext from a servlet?
Date Thu, 07 Jun 2007 19:13:08 GMT
As Jan-Kees says, you can directly access them from the session map.
If that doesn't appeal to you (or you want to do something more
complicated), you can use this technique.   Just remember to dispose
of the FacesContext when you're done with it.

On 6/7/07, Jan-Kees van Andel <> wrote:
> You only have a FacesContext when you are in a... Faces Context, which
> means, code that gets called by the Faces Servlet. For example, a Managed
> Bean or Converter, etcetera. Session scoped managed beans are stored in the
> session under their managed bean name, so you can access them directly from
> the httpsession.
> If I'm right, Seam and Shale have MockFacesContext classes which may be of
> use if you use any of these frameworks.
> Greets,
> Jan-Kees
> -----Oorspronkelijk bericht-----
> Van: Thai Dang Vu []
> Verzonden: donderdag 7 juni 2007 20:49
> Aan:
> Onderwerp: How to get the FacesContext from a servlet?
> Hi,
> My environment: JSF 1.2, Facelets, a4j, richfaces, spring, hibernate ...
> This is what I'm doing:
> I have a xhtml page that displays data in a dataTable. I'd like to
> provide a link (not a button) on that page so that user can get a csv
> version of the list. This tutorial
> ( is
> excellent, but it requires a button to do the download while I need a
> link. So I write a servlet for this download purpose like the example
> To get the data, I need to access a session-scope JSF bean. So I use:
>         FacesContext facesContext = FacesContext.getCurrentInstance();
>         Application app = facesContext.getApplication();
>         ExpressionFactory exFactory = app.getExpressionFactory();
>         SinglePage singlePage =
>                 (SinglePage)
> exFactory.createValueExpression(facesContext.getELContext(),
>                         "#{singlePage}", SinglePage.class)
>                         .getValue(facesContext.getELContext());
> but the facesContext is null. So is there any other way to get the
> facesContext? Or I have to get that JSF bean by looking in the session
> scope?
> Regards.
> NOTICE: This message (including any attachments) from Momentum Systems, Inc.
> contains information that is PRIVILEGED and CONFIDENTIAL.  If you are not an
> intended recipient, you are hereby notified that any dissemination of this
> message is strictly prohibited.  If you have received this message in error,
> please do not read, copy or forward this message.  Please permanently delete
> all copies and any attachments and notify the sender immediately by reply
> email or by calling our Office at 703.740.9300.

View raw message