10 Replies Latest reply on Feb 17, 2009 1:27 PM by jamon

    rich:comboBox  - how to bind value item and label item

      Hello all! I use rich:comboBox with ArrayList of SelectItem items:

      List items = new ArrayList();
      for(int i=0;i<10;i++)
      {
      items.add(new SelectItem(i, "item "+i));
      // there are I create new SelectItem object with value=i and label =
      //"item"+i
      }
      


      Now I bind my rich:comboBox to array like this:

      <rich:comboBox id="combo" style="width:100%; align: center"
      value="#{myBean.items}"/>
      


      And it's no good. In browser I catch one large, comma-separated string of toString() representation of each SelectItem object in my comboBox (e.g., javax.faces.model.SelectItem@1052a99, javax.faces.model.SelectItem@3828b11 and so on)

      Next, I try this approach:
      <rich:comboBox id="combo" style="width:100%; align: center"
      valueChangeListener="#{myBean.valueChanged}>
       <f:selectItems value="#{myBean.items}" id="items"/>
      </rich:comboBox>
      


      In this case I viewed labels in my comboBox, but there are some strange exceptions.

      First, I create each SelectItem object like this:
      ...
      new SelectItem(value, label);
      


      i.e. value - is a some number, and label - string-representation of this item. But in comboBox I see instead labels it's values collegues. And HTML contains only values items, not labels.

      Second, in debug mode I can't catch valueChanged method after change value in comboBox (in browser) - this event was not fired.

      Next, I use simple jsf code:
      <h:selectOneListbox size="0" valueChangeListener="#{myBean.valueChanged}">
      <f:selectItems value="#{myBean.items}" />
      </h:selectOneListbox>
      


      In this case I get in HTML option set, and id and labels typed properly. But valueChangeListener also don't fired, and in Java code I can't catch it.

      Please, review my issue and, if it's possible, help me:)