Ejemplo n.º 1
0
  protected List<SelectItem> getSelectItems(FacesContext context, UIInput component) {
    List<SelectItem> selectItems = new ArrayList<SelectItem>();

    for (UIComponent child : component.getChildren()) {
      if (child instanceof UISelectItem) {
        UISelectItem uiSelectItem = (UISelectItem) child;
        Object selectItemValue = uiSelectItem.getValue();

        if (selectItemValue == null) {
          selectItems.add(
              new SelectItem(
                  uiSelectItem.getItemValue(),
                  uiSelectItem.getItemLabel(),
                  uiSelectItem.getItemDescription(),
                  uiSelectItem.isItemDisabled(),
                  uiSelectItem.isItemEscaped(),
                  uiSelectItem.isNoSelectionOption()));
        } else {
          selectItems.add((SelectItem) selectItemValue);
        }

      } else if (child instanceof UISelectItems) {
        UISelectItems uiSelectItems = ((UISelectItems) child);
        Object value = uiSelectItems.getValue();

        if (value != null) {
          if (value instanceof SelectItem) {
            selectItems.add((SelectItem) value);
          } else if (value.getClass().isArray()) {
            for (int i = 0; i < Array.getLength(value); i++) {
              Object item = Array.get(value, i);

              if (item instanceof SelectItem) selectItems.add((SelectItem) item);
              else selectItems.add(createSelectItem(context, uiSelectItems, item));
            }
          } else if (value instanceof Map) {
            Map map = (Map) value;

            for (Iterator it = map.keySet().iterator(); it.hasNext(); ) {
              Object key = it.next();

              selectItems.add(
                  createSelectItem(context, uiSelectItems, String.valueOf(key), map.get(key)));
            }
          } else if (value instanceof Collection) {
            Collection collection = (Collection) value;

            for (Iterator it = collection.iterator(); it.hasNext(); ) {
              Object item = it.next();
              if (item instanceof SelectItem) selectItems.add((SelectItem) item);
              else selectItems.add(createSelectItem(context, uiSelectItems, item));
            }
          }
        }
      }
    }

    return selectItems;
  }