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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:58:06+00:00 2026-06-18T18:58:06+00:00

Using JSF2 (MyFaces 2.1) and CDI (Weld) I use a selectOneMenu filled with an

  • 0

Using JSF2 (MyFaces 2.1) and CDI (Weld) I use a selectOneMenu filled with an enum to conditionally render a second selectOneMenu (doublemenu in the code). There are several other fields in the form which are validated using bean validation.

The problem:

If there are validation errors after clicking on the commandButton and error messages are shown, the doublemenu will not reappear. It appears that bean.type ==’double’ is not true. But why? The selectOneMenu itself shows the option double as the selected item.

@javax.inject.Named
@javax.enterprise.context.RequestScoped
public class Bean {

private enum MyEnum {
    Single, Double
}

private MyEnum type;

public MyEnum getType() {
    return type;
}

public void setType(MyEnum type) {
    this.type = type;
}

public MyEnum [] getTypes() {
    return MyEnum.values();
}


<h:form>
<h:selectOneMenu value="#{bean.type}">
  <f:selectItems value="#{bean.types}" />
  <f:ajax render="doublemenu" />
</h:selectOneMenu>

<h:panelGroup id="doublemenu">
  <h:panelGroup rendered="#{bean.type == 'double'}">
    <h:selectOneMenu ...>
    </h:selectOneMenu>
  </h:panelGroup>
</h:panelGroup>
<h:inputText id="VALIDATED"/>
<h:commandButtonaction="#{bean.save}"
</h:form>

BTW: bean.save is not executed

  • 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-18T18:58:07+00:00Added an answer on June 18, 2026 at 6:58 pm

    It’s because your bean is request scoped. Request scoped beans are garbaged by end of every request and newly created on begin of every request. This also applies to individual ajax requests on the same view.

    The rendered attribute is also evaluated during collecting submitted values (the apply request values phase). However, at the point the submitted values are to be collected, the #{bean.type} is obviously not been set yet (it has still to be set based on the collected submitted value during update model values phase). As your bean is request scoped, it would return the default value, not the submitted value from a previous request.

    There are basically 2 ways to fix this.

    1. Put the bean in a bit broader scope. JSF offers the @ViewScoped for exactly this purpose. This is in the current JSF 2.1 version only not compatible with CDI. If switching to JSF @ManagedBean is not an option, then you’d need MyFaces CODI to bridge the JSF @ViewScoped transparently to CDI, or to wait for JSF 2.2 to get a CDI compatible @ViewScoped out the box.

    2. Check a request parameter instead of a bean property.

      <h:selectOneMenu binding="#{type}" ...>
          ...
      </h:selectOneMenu>
      
      <h:panelGroup rendered="#{param[type.clientId] == 'Double'}">
      

    Please note that this all is completely unrelated to enums. You’d have had exactly the same problem when using e.g. a String. Also please note that I fixed a typo in your code example, an enum value of Double is definitely not the same as double.

    See also:

    • How to choose the right bean scope?
    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using JBoss6.1.Final, JSF 2.0 (Mojarra), Weld CDI, MyFaces CODI 1.0.5 (for view-access-scoped) I'm
i want to use jQuery to sync values of JSF2 components. We are using
I am using JSF2 facelets. I am trying to insert a piece of code
I was using JBoss 7 with JSF 2.0 (Mojarra) and Weld as CDI. Everything
I am using jsf2.0 with icefaces3. I have a selectonemenu populated with a map
I developed a simple demo web application using JSF2.0 and hibernate. This webapp use
When using CDI and JSF2 How can a HTTP request parameter be injected into
Using jsf2 (see maven dependencies ) <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.1.10</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-api</artifactId>
I am using jsf2.0 with primefaces.My application was working fine with all browsers includes
I am using JSF2 with Pure JPA2. But the problem is with entityManager, @PersistenceContext

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.