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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:40:56+00:00 2026-05-31T05:40:56+00:00

Where is the proper ‘place’ in JSF to put initialisation snippet that follows, in

  • 0

Where is the proper ‘place’ in JSF to put initialisation snippet that follows, in order to get it executed just one time when the server starts?

1.  ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
2.  HttpSession sesion = (HttpSession)extContext.getSession(true); 
3.  String parA = extContext.getInitParameter("parA");
4.  String parB = someCalculations(parA);       
5.  sesion.setAttribute("parB", parB);

Basically I want to read a parameter parA from web.xml context-param section, do some transformations, and include it in session (as new parB parameter).

PostConstructApplicationEvent and eager=true techniques doesn’t works because session is null at this point (line 4).
ServletContextListener technique doesn’t works because FacesContext isn’t available.

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-05-31T05:40:57+00:00Added an answer on May 31, 2026 at 5:40 am

    There are no sessions at application start time; this requirement is impossible to meet.

    I interpret your requirements as:

    • perform an expensive application-scope calculation
    • inject this application-scope result into other scopes

    The JSF way to do this is via managed beans. Here is an application-scope bean to perform the one-time transformation of the context parameter:

    package foo;
    
    import javax.faces.bean.ApplicationScoped;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    
    @ManagedBean
    @ApplicationScoped
    public class SomeCalculationsBean {
      @ManagedProperty("#{initParam.paraA}")
      private String paraA;
    
      private String someCalculation;
    
      public String getParaA() {
        return paraA;
      }
    
      public void setParaA(String paraA) {
        this.paraA = paraA;
        this.someCalculation = //do some transformation
      }
    
      public String getSomeCalculation() {
        return someCalculation;
      }
    }
    

    This value can then be injected into other scopes as you need it:

    package foo;
    
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.ManagedProperty;
    import javax.faces.bean.SessionScoped;
    
    @ManagedBean
    @SessionScoped
    public class SomeSessionBean {
      @ManagedProperty("#{someCalculationsBean.someCalculation}")
      private String paraB;
    
      public String getParaB() {
        return paraB;
      }
    
      public void setParaB(String paraB) {
        this.paraB = paraB;
      }
    }
    

    Code untested. This implementation assumes JSF annotation support but you can do the same thing with faces-config.xml bean configuration.

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

Sidebar

Related Questions

QUESTION: What is the proper way to use .get() in conjunction with .one() (or
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
What would be the proper way to style multiple h6 headings differently on one
What is the proper way to declare a namespace? I've just read Developing Large
What is the proper way to release an array that you created with copy?
Assuming the proper tables are in place - what is the difference between the
what is the proper way to scale an SDL Surface? I found one explanation
How can I get proper redirection from an OAuth site to my CodeIgniter site
EDIT : proper solution: void add(Student s) { if(root == null) root = new
What is the proper (browser agnostic) way to disable page caching in ASP.NET MVC?

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.