Package javax.faces.model

Examples of javax.faces.model.SelectItem


                    boolean noSelectionOption = uiSelectItem.isNoSelectionOption();
                    if (label == null)
                    {
                        label = itemValue.toString();
                    }
                    item = new SelectItem(itemValue, label, description, disabled, escape, noSelectionOption);
                }
                else if (!(item instanceof SelectItem))
                {
                    ValueExpression expression = uiSelectItem.getValueExpression("value");
                    throw new IllegalArgumentException("ValueExpression '"
                            + (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : "
                            + RendererUtils.getPathToComponent(child) + " does not reference an Object of type SelectItem");
                }
                _nextItem = (SelectItem) item;
                return true;
            }
            else if (child instanceof UISelectItems)
            {
                _currentUISelectItems = ((UISelectItems) child);
                Object value = _currentUISelectItems.getValue();

                if (value instanceof SelectItem)
                {
                    _nextItem = (SelectItem) value;
                    return true;
                }
                else if (value != null && value.getClass().isArray())
                {
                    // value is any kind of array (primitive or non-primitive)
                    // --> we have to use class Array to get the values
                    final int length = Array.getLength(value);
                    Collection<Object> items = new ArrayList<Object>(length);
                    for (int i = 0; i < length; i++)
                    {
                        items.add(Array.get(value, i));
                    }
                    _nestedItems = items.iterator();
                    return hasNext();
                }
                else if (value instanceof Iterable)
                {
                    // value is Iterable --> Collection, DataModel,...
                    _nestedItems = ((Iterable<?>) value).iterator();
                    return hasNext();
                }
                else if (value instanceof Map)
                {
                    Map<Object, Object> map = ((Map<Object, Object>) value);
                    Collection<SelectItem> items = new ArrayList<SelectItem>(map.size());
                    for (Map.Entry<Object, Object> entry : map.entrySet())
                    {
                        items.add(new SelectItem(entry.getValue(), entry.getKey().toString()));
                    }
                   
                    _nestedItems = items.iterator();
                    return hasNext();
                }
View Full Code Here


        {
            throw new NoSuchElementException();
        }
        if (_nextItem != null)
        {
            SelectItem value = _nextItem;
            _nextItem = null;
            return value;
        }
        if (_nestedItems != null)
        {
            Object item = _nestedItems.next();
           
            if (!(item instanceof SelectItem))
            {
                // check new params of SelectItems (since 2.0): itemValue, itemLabel, itemDescription,...
                // Note that according to the spec UISelectItems does not provide Getter and Setter
                // methods for this values, so we have to use the attribute map
                Map<String, Object> attributeMap = _currentUISelectItems.getAttributes();
               
                // write the current item into the request map under the key listed in var, if available
                boolean wroteRequestMapVarValue = false;
                Object oldRequestMapVarValue = null;
                final String var = (String) attributeMap.get(VAR_ATTR);
                if(var != null && !"".equals(var))
                {
                    // save the current value of the key listed in var from the request map
                    oldRequestMapVarValue = _facesContext.getExternalContext().getRequestMap().put(var, item);
                    wroteRequestMapVarValue = true;
                }
               
                // check the itemValue attribute
                Object itemValue = attributeMap.get(ITEM_VALUE_ATTR);
                if (itemValue == null)
                {
                    // the itemValue attribute was not provided
                    // --> use the current item as the itemValue
                    itemValue = item;
                }
               
                // Spec: When iterating over the select items, toString()
                // must be called on the string rendered attribute values
                Object itemLabel = attributeMap.get(ITEM_LABEL_ATTR);
                if (itemLabel == null)
                {
                    itemLabel = itemValue.toString();
                }
                else
                {
                    itemLabel = itemLabel.toString();
                }
                Object itemDescription = attributeMap.get(ITEM_DESCRIPTION_ATTR);
                if (itemDescription != null)
                {
                    itemDescription = itemDescription.toString();
                }
                Boolean itemDisabled = getBooleanAttribute(_currentUISelectItems, ITEM_DISABLED_ATTR, false);
                Boolean itemLabelEscaped = getBooleanAttribute(_currentUISelectItems, ITEM_LABEL_ESCAPED_ATTR, true);
                Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_ATTR);
                item = new SelectItem(itemValue,
                        (String) itemLabel,
                        (String) itemDescription,
                        itemDisabled,
                        itemLabelEscaped,
                        itemValue.equals(noSelectionValue));
View Full Code Here

    private Date value3;
    private List<SelectItem> items;
    private TimeZone timeZone = TimeZone.getTimeZone("UTC");

    public PlaceHolderValue() {
        items = Lists.newArrayList(new SelectItem("item1", "item1"), new SelectItem("item2", "item2"));
    }
View Full Code Here

        UISelectOne selectOne = new UISelectOne();
        selectOne.getChildren().add(new UISelectItemStub("value1", "label1", "description1", false, false, false));
        selectOne.getChildren().add(new UISelectItemStub("value2", "label2", "description2", false, true, true));

        UISelectItem item = new UISelectItem();
        item.setValue(new SelectItem("value3", "label3", "description3", true, true, true));
        selectOne.getChildren().add(item);

        // non select item at end
        UIParameter param = new UIParameter();
        param.setName("param");
View Full Code Here

        @Override
        protected SelectItem computeNext() {
            if (data.hasNext()) {
                Entry<?, ?> next = (Entry<?, ?>) data.next();

                return new SelectItem(next.getValue(), next.getKey().toString());
            }

            return endOfData();
        }
View Full Code Here

        @Override
        protected SelectItem computeNext() {
            while (items.hasNext() || children.hasNext()) {
                if (items.hasNext()) {
                    SelectItem nextItem = items.next();

                    if (!items.hasNext()) {
                        // free iterator
                        items = Iterators.emptyIterator();
                    }
View Full Code Here

        }

        private Iterator<SelectItem> createUISelectItemIterator(UISelectItem selectItem) {
            Object value = selectItem.getValue();

            SelectItem result = null;

            if (value == null) {
                result = new SelectItem(selectItem.getItemValue(), selectItem.getItemLabel(), selectItem.getItemDescription(),
                    selectItem.isItemDisabled(), selectItem.isItemEscaped(), selectItem.isNoSelectionOption());
            } else if (value instanceof SelectItem) {
                result = (SelectItem) value;
            } else {
                ValueExpression expression = selectItem.getValueExpression("value");
View Full Code Here

    @PostConstruct
    public void init() {
        capitalsOptions = new ArrayList<SelectItem>();
        for (Capital capital : capitals) {
            capitalsOptions.add(new SelectItem(capital.getName(), capital.getState()));
        }
    }
View Full Code Here

      UIComponent child = children.next();
     
      if(child instanceof UISelectItem) {
        UISelectItem selectItem = (UISelectItem) child;
       
        items.add(new SelectItem(selectItem.getItemValue(), selectItem.getItemLabel()));
      } else if(child instanceof UISelectItems) {
        Object selectItems = ((UISelectItems) child).getValue();
     
        if(selectItems instanceof SelectItem[]) {
          SelectItem[] itemsArray = (SelectItem[]) selectItems;
         
          for(SelectItem item : itemsArray)
            items.add(new SelectItem(item.getValue(), item.getLabel()));
         
        } else if(selectItems instanceof Collection) {
          Collection<SelectItem> collection = (Collection<SelectItem>) selectItems;
         
          for(SelectItem item : collection)
            items.add(new SelectItem(item.getValue(), item.getLabel()));
        }
      }
    }
   
    return items;
View Full Code Here

        // If you change something here please do the same in the other class!
       
        Converter converter = null;
        while (converter == null && iterator.hasNext())
        {
            SelectItem item = iterator.next();
            if (item instanceof SelectItemGroup)
            {
                Iterator<SelectItem> groupIterator = Arrays.asList(((SelectItemGroup) item).getSelectItems()).iterator();
                converter = getSelectItemsValueConverter(groupIterator, facesContext);
            }
            else
            {
                Class<?> selectItemsType = item.getValue().getClass();
               
                // optimization: no conversion for String values
                if (String.class.equals(selectItemsType))
                {
                    return null;
View Full Code Here

TOP

Related Classes of javax.faces.model.SelectItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.