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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:53:58+00:00 2026-05-23T03:53:58+00:00

I have a SessionScoped bean say UserSession which holds a String property token which

  • 0

I have a SessionScoped bean say UserSession which holds a String property token which acts as a authenticated token for the logged in user. This token is injected into other SessionScoped and ViewScoped beans so that they can consume this token and perform stuff. I have no problems injecting the property.

However, there’s a use case wherein the token in the UserSession itself is replaced by a different String. And once I do this, the other beans still refer to the old value of the token which results in invalid access.

How can I notify the other beans of this value change? or do I retrieve bean instance through

FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
UserSession session = (UserSession) app.evaluateExpressionGet(context, "#{userSession}", UserSession.class);

And then retrieve token as session.getToken()?
I’m using Mojarra 2.0.4

  • 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-05-23T03:53:59+00:00Added an answer on May 23, 2026 at 3:53 am

    I don’t see why that is a problem. This more sounds like as if you’re copying the property like as:

    @ManagedBean
    @SessionScoped
    private OtherBean {
    
        @ManagedProperty(value="#{userSession}")
        private UserSession userSession;
    
        private String token;
    
        @PostConstruct
        public void init() { 
            this.token = userSession.getToken();
        }
    
        public void someAction() {
            doSomethingWith(token);
        }
    
        public void otherAction() {
            doSomethingElseWith(token);
        }
    
        // ...
    }
    

    while you should rather be accessing it directly:

        // ...
    
        public void someAction() {
            doSomethingWith(userSession.getToken());
        }
    
        public void otherAction() {
            doSomethingElseWith(userSession.getToken());
        }
    
        // ...
    

    Fix your beans accordingly to get rid of the private token property which contains the copy and just let all methods get it from the injected bean directly.

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

Sidebar

Related Questions

I have already one session scoped CDI bean, which keeps currently logged in user
I have a Session scoped bean @SessionScoped public class UserData implements Serializable { private
I have a session scoped managed bean, with a property current . If I
I have a strange problem. Afaik I can inject a SessionScoped bean into a
I have this managed bean: package com.DX_57.SR_57; /** include default packages for Beans */
How is the session defined in @SessionScoped CDI bean? Is this annotation valid only
I have this configuration on my web application. 2 beans : 1° Bean -
I have a JSF 2.0 bean: @ManagedBean @SessionScoped public class LoginBean implements Serializable {
I have a managed bean called: @ManagedBean(name=configBean) @SessionScoped public class configBean implements Serializable {
I have a controller that is stateless which takes care of processing forms. This

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.