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 8831171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:15:07+00:00 2026-06-14T08:15:07+00:00

This is a rookie question, sorry. I developed a jsf-2 app (on Tomcat) which

  • 0

This is a rookie question, sorry.

I developed a jsf-2 app (on Tomcat) which has a big controller bean declared in session scope.

Now, the mistake I made was to put all session scoped variables in this bean as static variables, thinking they would not be shared between different instances of the app. But they are – static variables are shared across all instances of the app on a same JVM, which makes sense actually. Anyway, all my code is currently like that:

@SessionScoped
@ManagedBean
public ControllerBean{
static private String aString = "session wide value for a string";
//static getter and setter for astring

}

@viewscoped
@ManagedBean
public class OneRandomViewScopedBean{
String oneString = ControllerBean.getAString();
//operations on this string...
ControllerBean.setAString(newValueForString);
} 

Could I get pointers as to how I should refactor my code to remove the static variables in my ControllerBean? I suppose the solution is dead simple but I can’t see it now.

Note: I don’t need to persist the data because the volumes are small and they can vanish after the app is closed

Thx!

  • 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-14T08:15:08+00:00Added an answer on June 14, 2026 at 8:15 am

    Remove the static modifier (that was indeed a huge mistake; this problem is not JSF specific, but just basic Java. I’d really invest some more time in learning basic Java before continuing with JSF) and use @ManagedProperty to inject other beans or its properties.

    @ManagedBean
    @SessionScoped
    public class ControllerBean {
    
        private String aString = "session wide value for a string";
        // Non-static getter and setter for aString.
    
        // ...
    }
    
    @ManagedBean
    @ViewScoped
    public class OneRandomViewScopedBean {
    
        @ManagedProperty("#{controllerBean}")
        private ControllerBean controllerBean;
        // Setter for controllerBean. Getter is not mandatory.
    
        public void someAction() {
            controllerBean.setAString(newValueForString);
        }
    
        // ...
    } 
    

    See also:

    • Communication in JSF 2.0 – Injecting managed beans in each other
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry that this may seem like a rookie question, but it's a real pain
This might be a really rookie question, but I'm writing an Android app that
This is obviously a rookie question about Adobe technologies, but I am seeking a
Rookie question, I think. I'm just trying to replicate this: http://rpubs.com/gallery/googleVis Open a new
I apologize for this, and I am sure it's a very rookie question... but
This is a rookie question. What's the best place to put @Resource private DataSource
This may be a rookie question but if I have created a suite of
This is probably a rookie question, but I need to know what I need
Rookie question, why this is not correct in Haskell? class BasicEq a where isEqual
This is extremely basic and I apologize for asking such a rookie question. But

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.