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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:51:20+00:00 2026-06-10T20:51:20+00:00

I have three combo boxes. The first one is populated with values. When I

  • 0

I have three combo boxes. The first one is populated with values. When I select a value from it, the second must be updated. After that, when I select a value from the second combo, the third should be populated. I know that this is already communicated, but with two combos. With more than two it is not working. Could you please tell me what I didn’t do properly?

Here is the view:

<h:form>
    <h:panelGrid columns="2">        
        <h:outputText value="Choose the produce type:"/>

        <h:selectOneMenu id="firstList"
                            value="#{userBean.firstItem}"                
                            valueChangeListener="#{userBean.valueChanged}">
            <f:selectItems value="#{userBean.firstList}"
                           var="element"
                           itemLabel="#{element.label}"
                           itemValue="#{element.value}" />
                <a4j:support reRender="outputPanel"
                             event="onchange"                                                                  
                             ajaxSingle="true"
                             bypassUpdates="false" />                
        </h:selectOneMenu>

        <a4j:outputPanel id="outputPanel">
            <h:selectOneMenu value="#{userBean.secondItem}"                
                             valueChangeListener="#{userBean.valueChanged}">
            <f:selectItems value="#{userBean.secondList}"
                           var="element"
                           itemLabel="#{element.label}"
                           itemValue="#{element.value}" />                    
                    <a4j:support reRender="outputPanel"
                             event="onchange"                                                                  
                             ajaxSingle="true"
                             bypassUpdates="false" />                                                 
            </h:selectOneMenu>

            <h:selectOneMenu value="#{userBean.thirdItem}"                
                             valueChangeListener="#{userBean.valueChanged}">
            <f:selectItems value="#{userBean.thirdList}"
                           var="element"
                           itemLabel="#{element.label}"
                           itemValue="#{element.value}" />                                                 
            </h:selectOneMenu>                
        </a4j:outputPanel>

    </h:panelGrid>
</h:form>

This is the Bean (this is a sample code without any meaningful sence):

@Name("userBean")
public class UserBean
{
@Logger private Log log;

@In StatusMessages statusMessages;

private String firstItem="";
private String secondItem="";
private String thirdItem="";
public List<SelectItem> firstList = new ArrayList<SelectItem>(); 
public List<SelectItem> secondList = new ArrayList<SelectItem>();
public List<SelectItem> thirdList = new ArrayList<SelectItem>();
private static final String [] FRUITS = {"Banana", "Cranberry", "Blueberry", "Orange"};
private static final String [] VEGETABLES = {"Potatoes", "Broccoli", "Garlic", "Carrot"};
private static final String [] GIRLS = {"Victoria", "Nana", "Etc.."};

public UserBean() {
    SelectItem item = new SelectItem("fruits", "Fruits");
    firstList.add(item);
    item = new SelectItem("vegetables", "Vegetables");
    firstList.add(item);
    item = new SelectItem("girls", "Girls");
    firstList.add(item);
    for (int i = 0; i < FRUITS.length; i++) {
        item = new SelectItem(FRUITS[i]);
    }
}

public List<SelectItem> getFirstList() {
    return firstList;
}

public List<SelectItem> getSecondList() {
    return secondList;
}

public List<SelectItem> getThirdList() {
    return thirdList;
}

public static String[] getFRUITS() {
    return FRUITS;
}

public static String[] getVEGETABLES() {
    return VEGETABLES;
}

public static String[] getGIRLS() {
    return GIRLS;
}

public void valueChanged(ValueChangeEvent event){
    String[] currentItems;
    String id = ((HtmlSelectOneMenu)event.getSource()).getId();
    if (id.equals("firstList")) {            
        currentItems = FRUITS;

        for (int i = 0; i < currentItems.length; i++) {
            SelectItem item = new SelectItem(currentItems[i]);
            secondList.add(item);
        }

        thirdList.clear();
    } else {
        currentItems = GIRLS;

        for (int i = 0; i < currentItems.length; i++) {
            SelectItem item = new SelectItem(currentItems[i]);
            thirdList.add(item);
        }
    }  
}

public String getFirstItem() {
    return firstItem;
}


public void setFirstItem(String firstItemArg) {
    firstItem = firstItemArg;
}


public String getSecondItem() {
    return secondItem;
}


public void setSecondItem(String secondItemArg) {
    secondItem = secondItemArg;
}

public String getThirdItem() {
    return thirdItem;
}


public void setThirdItem(String thirdItemArg) {
    thirdItem = thirdItemArg;
} 

The problem is that when I select a value from the second combo box (values of which were loaded dynamically), the page is reloaded (instead of ajax request being executed) and I have exception:

Exception during request processing:
Caused by javax.servlet.ServletException with message: “java.util.NoSuchElementException”

The second list is successfully updated from the first list, but after that something is wrong.

Thanks in advance!
Cheers!

  • 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-10T20:51:22+00:00Added an answer on June 10, 2026 at 8:51 pm

    Make sure your bean has a wider scope than Request, like Conversation scope. It looks like you’re using JSF 1.2, in this case RichFaces has a <a4j:keepAlive> tag component to elevate the scope of a managed bean from Request to View (using session variables behind the scenes). This option could be what you need. There are two ways to implement it

    1. Using the tag component. This will make the bean have the “View Scope” only for this page.

      <a4j:keepAlive bean="userBean" />
      <h:form>
          <h:panelGrid columns="2">
          <!-- the rest of your code... -->
      
    2. Using the tag annotation. This will make the bean have the “View Scope” on every page is used.

      @Name("userBean")
      @KeepAlive
      public class UserBean {
          //your managed bean code...
      }
      

    Note: To use this tag (as component or annotation), the bean must have Request scope.

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

Sidebar

Related Questions

I have two dependent combo-boxes and the value of second one is populated after
I have two combo boxes. Let's say the first one had values A, B,
I have a set of three combo boxes (drop downs) that are populated by
I have an application which is using a set of three combo boxes. I
I have three column in my datagridview .One is text ,one is Combo and
I have three text boxes having ids: textbox1, textbox2, textbox3. I am retrieving values
I have two combo boxes in wpf one of the combo boxes looks like
I have been creating Spinner controls (Combo boxes/Drop downs) in one of my apps,
I have tried to set up combo boxes in the gridview but all the
I have been trying to define multiple combo boxes in R using the tcltk

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.