Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:20:32+00:00 2026-06-17T08:20:32+00:00

I just started learning JSF. While working with an example, I felt the need

  • 0

I just started learning JSF.

While working with an example, I felt the need to access the ServletContext object inside MyBean class. I wanted to use an object which I had put inside the ServletContext using Listener. Can I do that? Does ServletContext has its scope inside Beans as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:20:33+00:00Added an answer on June 17, 2026 at 8:20 am

    It’s just available by ExternalContext#getContext(). See also its javadoc:

    getContext

    public abstract java.lang.Object getContext()

    Return the application environment object instance for the current appication.

    It is valid to call this method during application startup or shutdown. If called during application startup or shutdown, this returns the same container context instance (ServletContext or PortletContext) as the one returned when calling getContext() on the ExternalContext returned by the FacesContext during an actual request.

    Servlet: This must be the current application’s javax.servlet.ServletContext instance.

    So, this should do:

    public void someMethod() {
        ServletContext servletContext = (ServletContext) FacesContext
            .getCurrentInstance().getExternalContext().getContext();
        // ...
    }
    

    Unrelated to the concrete question, depending on the concrete functional requirement, this may not be the right solution to the concrete problem. General consensus is that your JSF code should be as much as possible free of any javax.servlet.* dependencies/imports. Your question isn’t exactly clear, but if you indeed intend to access an attribute which you’ve put in the servlet context, then just get it from ExternalContext#getApplicationMap() instead.

    E.g. in the ServletContextListener:

    event.getServletContext().setAttribute("foo", foo);
    

    and then in JSF

    Foo foo = (Foo) FacesContext.getCurrentInstance().getExternalContext()
        .getApplicationMap().get("foo");
    

    or even just by @ManagedProperty

    @ManagedProperty("#{foo}")
    private Foo foo; // +setter
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started learning Haskell. I have an empty source file with this inside: pe
I just started learning Zend. I managed to get the basic working (using zf
I just started learning SL. I have tried to resize all the elements inside
Just started learning Ruby metaprogramming. Looking at Object.methods I get: Object.methods => [ :allocate,
I just started learning php yesterday, and had a question about the example code
I just started learning java and I'm working on a program. I'm getting an
I just started learning about JSF. In JSP file we can use <%= request.getAttribute(JsData)%>
We just started learning about class inheritance and attribute lookup in python. I have
I just started learning RubyOnRail since some days. I need some rubyrails/ rails documentaton/api
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.