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

  • SEARCH
  • Home
  • 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 8805863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:58:25+00:00 2026-06-14T01:58:25+00:00

I use tomcat 7.0 and JSF 2.1 and I have problem when I call

  • 0

I use tomcat 7.0 and JSF 2.1 and I have problem when I call in my .xhtml page something like that: #{homePage.get("userName")}

I get javax.el.ELException: Caused by: java.lang.NullPointerException
at mainPacket.HomePageBean.get(HomePageBean.java:35)

I have ManagedBean like below:

@ManagedBean(name = "homePage")
@ViewScoped
public class HomePageBean {
    private Map<String, Object> map;

    public HomePageBean() {
        map= FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
        //remove unnecessary values from sessionMap
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().clear();

    }
    public String get(Object s){
        return map.get(s).toString();
    }
}

When I don’t use clear, everything works ok. But I want to clear sessionMap. How to resolve it ?
Thanks

  • 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-14T01:58:26+00:00Added an answer on June 14, 2026 at 1:58 am

    Java is an object oriented language. It doesn’t give you a copy of the object everytime you request it. No, it gives you a reference to the object instance in memory. At the moment you invoke Map#clear() on the session map, then the map reference which you obtained just beforehand is basically also emptied, because it points to exactly the same map instance which you just emptied!

    Your concrete functional requirement is nowhere mentioned in the question and the whole design in the code posted so far makes honestly no utter sense (I can’t imagine any sensible real world use case for this), so it’s hard to propose you the right solution. Best what you can get is the advice to add a nullcheck.

    public String get(Object s){
        Object value = map.get(s);
        return (value != null) ? value.toString() : null;
    }
    

    You should by the way be very careful with abruptly emptying the session map this way. JSF stores view scoped and session scoped managed beans in there and it’s also used by the flash scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use tomcat 5.5, JSF 1.2, Spring 3 I have the servlet that passes
I'm running a JSF 2.0 application on Tomcat 7. I want to use javascript
I use Tomcat 7 on Windows XP. I have a directory with static files
I try to get Tomcat to use BoneCP as a connection pool because DBCP
How Can I use my system as a tomcat server ? Like tomcat server
suppose, I use Tomcat as a web container. Is it true that once all
i want to use EL 2.2 for JSF 2 application and tomcat 7 is
I use tomcat-maven-plugin to deploy my war to a server. What I have to
Have xhtml templ.xhtml layout. Include it to other .xhtml like: <ui:composition template=/template/templ.xhtml> Define conditionals
I use Tomcat 7 together with CDI and for that I used the jee6-servlet-minimal-archetype

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.