Search in sources :

Example 1 with UISelectItem

use of javax.faces.component.UISelectItem in project gdmatrix by gdmatrix.

the class HtmlCommandMenu method getSelectItems.

private List<SelectItem> getSelectItems() {
    List<SelectItem> selectItems = new ArrayList();
    Iterator iter = getChildren().iterator();
    while (iter.hasNext()) {
        UIComponent component = (UIComponent) iter.next();
        if (component instanceof UISelectItem) {
            UISelectItem uiSelectItem = (UISelectItem) component;
            SelectItem selectItem = (SelectItem) uiSelectItem.getValue();
            if (selectItem == null) {
                selectItem = new SelectItem(uiSelectItem.getItemValue(), uiSelectItem.getItemLabel());
            }
            selectItems.add(selectItem);
        } else if (component instanceof UISelectItems) {
            UISelectItems siComponent = (UISelectItems) component;
            Object items = siComponent.getValue();
            if (items instanceof SelectItem[]) {
                for (SelectItem selectItem : (SelectItem[]) items) {
                    selectItems.add(selectItem);
                }
            } else if (items instanceof Collection) {
                Collection col = (Collection) items;
                for (Object item : col) {
                    if (item instanceof SelectItem) {
                        selectItems.add((SelectItem) item);
                    }
                }
            }
        }
    }
    return selectItems;
}
Also used : UISelectItems(javax.faces.component.UISelectItems) SelectItem(javax.faces.model.SelectItem) UISelectItem(javax.faces.component.UISelectItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) Collection(java.util.Collection) UISelectItem(javax.faces.component.UISelectItem)

Example 2 with UISelectItem

use of javax.faces.component.UISelectItem in project gdmatrix by gdmatrix.

the class HtmlAutocomplete method getSelectItems.

private List<SelectItem> getSelectItems() {
    List<SelectItem> selectItems = new ArrayList();
    Iterator iter = getChildren().iterator();
    while (iter.hasNext()) {
        UIComponent component = (UIComponent) iter.next();
        if (component instanceof UISelectItem) {
            UISelectItem uiSelectItem = (UISelectItem) component;
            SelectItem selectItem = (SelectItem) uiSelectItem.getValue();
            if (selectItem == null) {
                selectItem = new SelectItem(uiSelectItem.getItemValue(), uiSelectItem.getItemLabel());
            }
            selectItems.add(selectItem);
        } else if (component instanceof UISelectItems) {
            UISelectItems siComponent = (UISelectItems) component;
            Object items = siComponent.getValue();
            if (items instanceof SelectItem[]) {
                for (SelectItem selectItem : (SelectItem[]) items) {
                    selectItems.add(selectItem);
                }
            } else if (items instanceof Collection) {
                Collection col = (Collection) items;
                for (Object item : col) {
                    if (item instanceof SelectItem) {
                        selectItems.add((SelectItem) item);
                    }
                }
            }
        }
    }
    return selectItems;
}
Also used : UISelectItems(javax.faces.component.UISelectItems) SelectItem(javax.faces.model.SelectItem) UISelectItem(javax.faces.component.UISelectItem) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) Collection(java.util.Collection) UISelectItem(javax.faces.component.UISelectItem)

Example 3 with UISelectItem

use of javax.faces.component.UISelectItem in project liferay-faces-alloy by liferay.

the class AutoComplete method getAllItems.

public final List<String> getAllItems(FacesContext facesContext) {
    List<String> allItems = new ArrayList<String>();
    List<UIComponent> children = getChildren();
    for (UIComponent child : children) {
        if (child instanceof UISelectItem) {
            UISelectItem uiSelectItem = (UISelectItem) child;
            Object itemValue = uiSelectItem.getItemValue();
            if (itemValue != null) {
                allItems.add(itemValue.toString());
            }
        } else if (child instanceof UISelectItems) {
            UISelectItems uiSelectItems = (UISelectItems) child;
            Object value = uiSelectItems.getValue();
            if (value != null) {
                if (value instanceof SelectItem) {
                    SelectItem selectItem = (SelectItem) value;
                    Object item = selectItem.getValue();
                    if (item != null) {
                        allItems.add(item.toString());
                    }
                } else if (value.getClass().isArray()) {
                    int length = Array.getLength(value);
                    for (int i = 0; i < length; i++) {
                        Object itemValue = Array.get(value, i);
                        String item = getItemValue(facesContext, uiSelectItems, itemValue);
                        if (item != null) {
                            allItems.add(item);
                        }
                    }
                } else if (value instanceof Collection) {
                    Collection<?> collection = (Collection<?>) value;
                    Iterator<?> iterator = collection.iterator();
                    while (iterator.hasNext()) {
                        String item = getItemValue(facesContext, uiSelectItems, iterator.next());
                        if (item != null) {
                            allItems.add(item);
                        }
                    }
                } else if (value instanceof Map) {
                    Map<?, ?> map = (Map<?, ?>) value;
                    Iterator<?> iterator = map.keySet().iterator();
                    while (iterator.hasNext()) {
                        Object key = iterator.next();
                        String item = getItemValue(facesContext, uiSelectItems, map.get(key));
                        if (item != null) {
                            allItems.add(item);
                        }
                    }
                } else {
                    throw new IllegalArgumentException();
                }
            }
        }
    }
    return Collections.unmodifiableList(allItems);
}
Also used : UISelectItems(javax.faces.component.UISelectItems) ArrayList(java.util.ArrayList) UIComponent(javax.faces.component.UIComponent) UISelectItem(javax.faces.component.UISelectItem) SelectItem(javax.faces.model.SelectItem) UISelectItem(javax.faces.component.UISelectItem) Iterator(java.util.Iterator) Collection(java.util.Collection) Map(java.util.Map)

Example 4 with UISelectItem

use of javax.faces.component.UISelectItem in project empire-db by apache.

the class SelectInputControl method syncOptions.

public void syncOptions(UISelectOne input, TextResolver textResolver, InputInfo ii) {
    // get the options
    Options options = ii.getOptions();
    if (options == null) {
        // clear or not?
        if (ii.getValue(false) != null)
            log.warn("No options have been set for column {}", ii.getColumn().getName());
        else
            input.getChildren().clear();
        return;
    }
    Object currentValue = ii.getValue(true);
    boolean hasEmpty = isEmptyEntryRequired(input, options, ii, currentValue);
    // boolean isInsideUIData = ii.isInsideUIData();
    // Compare child-items with options
    Iterator<OptionEntry> ioe = options.iterator();
    OptionEntry oe = (ioe.hasNext() ? ioe.next() : null);
    List<UIComponent> childList = input.getChildren();
    Iterator<UIComponent> ico = childList.iterator();
    int lastIndex = 0;
    boolean emptyPresent = false;
    while (ico.hasNext()) {
        lastIndex++;
        UIComponent co = ico.next();
        if (!(co instanceof UISelectItem))
            continue;
        UISelectItem si = (UISelectItem) co;
        Object ov = si.getItemValue();
        if (ObjectUtils.isEmpty(ov) && hasEmpty) {
            emptyPresent = true;
            continue;
        }
        // skip inactive
        while (oe != null && !oe.isActive()) {
            // check for current
            if (ObjectUtils.compareEqual(oe.getValue(), currentValue))
                break;
            // next oe
            oe = (ioe.hasNext() ? ioe.next() : null);
        }
        if (oe == null) {
            // remove obsolete items
            lastIndex--;
            for (int index = childList.size() - 1; index >= lastIndex; index--) childList.remove(index);
            // done
            return;
        }
        if (ObjectUtils.compareEqual(ov, oe.getValue())) {
            // next
            String label = oe.getText();
            si.setItemLabel(textResolver.resolveText(label));
            oe = (ioe.hasNext() ? ioe.next() : null);
            continue;
        }
        // Not equal - do a full reload
        input.getChildren().clear();
        if (hasEmpty) {
            // add empty entry
            addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)));
        }
        for (OptionEntry opt : options) {
            // Option entries
            if (opt.isActive() || ObjectUtils.compareEqual(opt.getValue(), currentValue)) {
                // add active or current item
                addSelectItem(input, textResolver, opt);
            }
        }
        // done
        return;
    }
    // check empty entry
    if (hasEmpty && !emptyPresent) {
        // add missing empty entry
        addSelectItem(input, textResolver, new OptionEntry("", getNullText(ii)), 0);
    }
    // Are there any items left?
    while (oe != null) {
        // add missing item
        if (oe.isActive() || ObjectUtils.compareEqual(oe.getValue(), currentValue)) {
            // add item
            addSelectItem(input, textResolver, oe);
        }
        oe = (ioe.hasNext() ? ioe.next() : null);
    }
}
Also used : Options(org.apache.empire.commons.Options) OptionEntry(org.apache.empire.commons.OptionEntry) UIComponent(javax.faces.component.UIComponent) UISelectItem(javax.faces.component.UISelectItem)

Example 5 with UISelectItem

use of javax.faces.component.UISelectItem in project empire-db by apache.

the class SelectInputControl method addSelectItem.

public void addSelectItem(UIComponent input, TextResolver textResolver, OptionEntry e, int pos) {
    UISelectItem selectItem = new UISelectItem();
    // set value
    Object value;
    Object valueExpressionFlag = input.getAttributes().get(SelectInputControl.VALUE_EXPRESSION_FLAG);
    if (ObjectUtils.getBoolean(valueExpressionFlag)) {
        // Use formatted value
        value = formatInputValue(e.getValue());
    } else {
        // Convert to String
        value = e.getValueString();
    }
    selectItem.setItemValue(value);
    // set text
    String text = e.getText();
    text = textResolver.resolveText(text);
    selectItem.setItemLabel(text);
    // add item
    if (pos >= 0)
        input.getChildren().add(pos, selectItem);
    else
        input.getChildren().add(selectItem);
}
Also used : UISelectItem(javax.faces.component.UISelectItem)

Aggregations

UISelectItem (javax.faces.component.UISelectItem)9 UIComponent (javax.faces.component.UIComponent)6 UISelectItems (javax.faces.component.UISelectItems)5 SelectItem (javax.faces.model.SelectItem)5 ArrayList (java.util.ArrayList)4 Collection (java.util.Collection)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 OptionEntry (org.apache.empire.commons.OptionEntry)2 List (java.util.List)1 RandomAccess (java.util.RandomAccess)1 Options (org.apache.empire.commons.Options)1