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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:39:03+00:00 2026-05-27T23:39:03+00:00

Facelet code: <h:selectOneMenu id = country label = country value = #{beanController.countryResidence}> <f:selectItems value

  • 0

Facelet code:

<h:selectOneMenu id = "country" label = "country" value = "#{beanController.countryResidence}">
    <f:selectItems value = "#{countries.countries}" />
</h:selectOneMenu>

Bean Code:

@ManagedBean(eager=true, name = "countries")
@ApplicationScoped
public class CountriesConstants {
        private List<SelectItem> countries;
        public CountriesConstants(){
            countries.add(new SelectItem("DE", "Germany"));
            countries.add(new SelectItem("JA", "Japan"));
            countries.add(new SelectItem("RU", "Russia"));
            countries.add(new SelectItem("US", "United States"));
        }
        public List<SelectItem> getCountries() {
            return countries;
        }
        public void setCountries(List<SelectItem> countries) {
            this.countries = countries;
        }
}

The Error

SEVERE: Exception while loading the app

SEVERE: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.RuntimeException: com.sun.faces.mgbean.ManagedBeanCreationException: Cant instantiate class: com.mysite.util.CountriesConstants.

I followed some tutorials step by step but I keep getting this error. I tried making the List static and initialise the values in a static block but I get the same error.

EDIT:

The new Bean Code

@ManagedBean(eager=true, name="constants")
@ApplicationScoped
public class Constants {

    public static final String VALIDATE_DETAILED = "detailed";
    public static final List<SelectItem> countries;

    static{
        countries = new ArrayList<SelectItem>();
        countries.add(new SelectItem("DE", "Germany"));
        countries.add(new SelectItem("JA", "Japan"));
        countries.add(new SelectItem("RU", "Russia"));
        countries.add(new SelectItem("US", "United States"));
    }

    public List<SelectItem> getCountries() {
        return countries;
    }
}

This seems to work but I find it weird that I can access a static attribute with a non static method. If I remove the getCOuntries() method an error saying that no countries attribute exists is thrown.

  • 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-27T23:39:04+00:00Added an answer on May 27, 2026 at 11:39 pm

    In your bean constructor, you must create your List first, try this:

    public CountriesConstants(){
       countries = new LinkedList<SelectItem>();
       countries.add(new SelectItem("DE", "Germany"));
       countries.add(new SelectItem("JA", "Japan"));
       countries.add(new SelectItem("RU", "Russia"));
       countries.add(new SelectItem("US", "United States"));
    }
    

    Besides, your <f:selectItems> tag should have more attribute. Something like this:

    <f:selectItems value="#{countries.countries}" var="c" itemLabel="#{c.name}" itemValue="#{c.id}" />
    

    UPDATE: suppose you have the following controller

    @ManagedBean
    @RequestScoped
    public class BeanController {
       private String countryResidence;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the follwing code inside a facelet page: <h:inputNumber value=bean.property> <f:convertNumber type=currency />
I have the following code: otroDemo.java: package beans; import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.ApplicationScoped;
I have Facelet component and I have backing bean for it. When I include
in a JSF facelet page (.xhtml) I have this javascript code <script type=text/javascript> function
I want some code in facelet (jsf 2.0) to work: <h:inputText id=q /> <h:button
I created a Facelet tag for rendering a textinput with a label. That's very
In a Facelet page that uses a Facelet Template like this: <h:head> <h:outputScript name=custom.js
This is my code in my managed bean :- <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE
Why does Glassfish shows this facelets error: javax.el.ELException: /foo/client.xhtml @11,74 value=#{messageBean.messages}: javax.mail.MessagingException: Socket closed;
This code, a test case for a custom component using JSF2 Just for the

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.