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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:45:35+00:00 2026-05-15T14:45:35+00:00

In a Screen to be rendered by a JSF Implementation, I had to show

  • 0

In a Screen to be rendered by a JSF Implementation, I had to show a static drop down or list box (which means the values are not changing ), So I decided to use a list of select Items and in the getter of the List , I am populating all the select Items as this

List.add(new SelectItem(VALUE,TEXT)) and so on.. 

If I used this way – What are the pitfalls? I made this List static since this will be common for all the Request Scoped Beans the JSF Implementation creates. Is this okay to do?

Sometimes , the items are added twice if multiple requests are fired.Is there an Application Scope ? or Whats the standard way of doing these stuff?

I’m also looking into API.Sometimes SO is quicker.

I’m using JSF Apace My Faces 1.2 without Tomahawk or any extra libs

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-15T14:45:36+00:00Added an answer on May 15, 2026 at 2:45 pm

    Sometimes , the items are added twice if multiple requests are fired.

    This indicates that you’re adding the items in the getter method like follows

    public class Bean {
        private List<SelectItem> items = new ArrayList<SelectItem>();
    
        public List<SelectItem> getItems() {
            items.add(new SelectItem("value1", "label1"));
            items.add(new SelectItem("value2", "label2"));
            items.add(new SelectItem("value3", "label3"));
            return items;
        }
    }
    

    This is not good. A javabean getter should have the sole purpose to return a bean property or at highest do lazy loading, not to do some business stuff. You should create and fill the list during bean construction

    public class Bean {
        private List<SelectItem> items;
    
        public Bean() {
            items = new ArrayList<SelectItem>();
            items.add(new SelectItem("value1", "label1"));
            items.add(new SelectItem("value2", "label2"));
            items.add(new SelectItem("value3", "label3"));
        }
    }
    

    or initialization

    public class Bean {
        private List<SelectItem> items;
    
        {
            items = new ArrayList<SelectItem>();
            items.add(new SelectItem("value1", "label1"));
            items.add(new SelectItem("value2", "label2"));
            items.add(new SelectItem("value3", "label3"));
        }
    }
    

    or @PostConstruct

    public class Bean {
        private List<SelectItem> items;
    
        @PostConstruct
        public void init() {
            items = new ArrayList<SelectItem>();
            items.add(new SelectItem("value1", "label1"));
            items.add(new SelectItem("value2", "label2"));
            items.add(new SelectItem("value3", "label3"));
        }
    }
    

    Is there an Application Scope ?

    There is. Just use <managed-bean-scope>application</managed-bean-scope>.

    or Whats the standard way of doing these stuff?

    An application scoped bean is the way to go.

    See also:

    • Why does JSF call getters multiple times?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a splash screen to show while the application is loading. I have
I have a 1920x1200 screen an would like to customize VS2008 code windows to
What is GNU Screen?
I use the screen command for command-line multitasking in Linux and I set my
I have a touch screen kiosk that displays a webpage and a pdf document.
I have a screen with a ListBox of items. The item template contains an
I'm writing a screen recording app for Windows in Delphi 7 and wish to
I have a login screen that I force to be ssl, so like this:
In some screen capture software when you press a key it's possible for the
How full-screen mode, like in web browsers, for application running under Windows OS is

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.