0

Long time no come by

I have a problem in filling a h: selectOneMenu in JSF, I can not make it display all records in the database, only shows the first 20 items

Any help is welcome, don't know if it is a configuration issue or something wrong with my code

This is my JSF code

<h:selectOneMenu value="#{myController.myValue}">
   <f:selectItems value="#{myController.itemsAvailableSelectOne}"  />
</h:selectOneMenu>

myController

public SelectItem[] getItemsAvailableSelectOne() {
    return JsfUtil.getSelectItems(ejbFacade.findAll(), true);
}

This is how i transform my List to SelectItem, Note that debugging I have come to see that the function returns 88 items

public static SelectItem[] getSelectItems(List<?> entities, boolean selectOne) {
        int size = selectOne ? entities.size() + 1 : entities.size();
        SelectItem[] items = new SelectItem[size];
        int i = 0;
        if (selectOne) {
            items[0] = new SelectItem("", "---");
            i++;
        }
        for (Object x : entities) {
            items[i++] = new SelectItem(x, x.toString());
        }
        return items;
    }

Thanks for your time and help

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
ErVeY
  • 1,524
  • 4
  • 16
  • 26
  • I think by using `items[i++]` you skipped one index at the beginning. Furthermore, you can also build a List instead of an Array, which should be easier. Are you sure that `x.toString()` is unique for every entity? – noone Oct 23 '13 at 04:55
  • You can find an easier solution using `List` in [StackOverflow selectonemenu wiki](http://stackoverflow.com/tags/selectonemenu/info), *Dynamic list of objects* section. If you're using JSF 1.2, it would be better using a `Map` backed by a `LinkedHashMap`. – Luiggi Mendoza Oct 23 '13 at 05:20
  • thx for the answer x.toString is not unique for the entity but i don't think that is a problem. And as far as i not, i don't skip the index at the begining because i++ increments it's value before the excecution of the line – ErVeY Oct 23 '13 at 12:57
  • all your entities are the same time of object? maybe the 21th cannot be converted properly –  Jan 19 '14 at 13:39

0 Answers0