Search in sources :

Example 1 with SelectItem

use of jakarta.faces.model.SelectItem in project rubia-forums by flashboss.

the class PreferenceController method getSummaryModeValues.

public SelectItem[] getSummaryModeValues() {
    SelectItem[] items = new SelectItem[SummaryMode.values().length];
    int i = 0;
    for (SummaryMode g : SummaryMode.values()) {
        items[i++] = new SelectItem(g, g.toString());
    }
    return items;
}
Also used : SummaryMode(it.vige.rubia.ui.view.SummaryMode) SelectItem(jakarta.faces.model.SelectItem)

Example 2 with SelectItem

use of jakarta.faces.model.SelectItem in project rubia-forums by flashboss.

the class Search method getCategoriesItems.

public Collection<SelectItem> getCategoriesItems() {
    Collection<SelectItem> categories = new ArrayList<SelectItem>();
    categories.add(new SelectItem("", "Search All Categories"));
    try {
        // Luca Stancapiano start
        // get the forumInstanceId where this forum should be added
        int forumInstanceId = userPreferences.getForumInstanceId();
        List<CategoryBean> c = forumsModule.findCategories(forumInstanceId);
        if (c != null) {
            for (CategoryBean category : c) {
                categories.add(new SelectItem(category.getId().toString(), category.getTitle()));
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
    return categories;
}
Also used : CategoryBean(it.vige.rubia.dto.CategoryBean) SelectItem(jakarta.faces.model.SelectItem) ArrayList(java.util.ArrayList) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException)

Example 3 with SelectItem

use of jakarta.faces.model.SelectItem in project rubia-forums by flashboss.

the class Search method getForumsItems.

public Collection<SelectItem> getForumsItems() {
    Collection<SelectItem> forums = new ArrayList<SelectItem>();
    forums.add(new SelectItem("", "Search All Forums"));
    try {
        // Luca Stancapiano start
        // get the forumInstanceId where this forum should be added
        int forumInstanceId = userPreferences.getForumInstanceId();
        List<ForumBean> f = forumsModule.findForums(forumInstanceId);
        if (f != null) {
            for (ForumBean forum : f) {
                forums.add(new SelectItem(forum.getId().toString(), forum.getName()));
            }
        }
    } catch (Exception e) {
        handleException(e);
    }
    return forums;
}
Also used : ForumBean(it.vige.rubia.dto.ForumBean) SelectItem(jakarta.faces.model.SelectItem) ArrayList(java.util.ArrayList) JSFUtil.handleException(it.vige.rubia.ui.JSFUtil.handleException)

Example 4 with SelectItem

use of jakarta.faces.model.SelectItem in project myfaces by apache.

the class SelectItemsIterator method hasNext.

@SuppressWarnings("unchecked")
@Override
public boolean hasNext() {
    if (_nextItem != null) {
        return true;
    }
    if (_nestedItems != null) {
        if (_nestedItems.hasNext()) {
            return true;
        }
        _nestedItems = null;
        _currentComponent = null;
        _currentValue = null;
    }
    if (_children.hasNext()) {
        UIComponent child = _children.next();
        // that conform this condition, just return false.
        while (!(child instanceof UISelectItem) && !(child instanceof UISelectItems)) {
            // Try to skip it
            if (_children.hasNext()) {
                // Skip and do the same check
                child = _children.next();
            } else {
                // since there are no more components to iterate.
                return false;
            }
        }
        if (child instanceof UISelectItem) {
            UISelectItem uiSelectItem = (UISelectItem) child;
            Object item = uiSelectItem.getValue();
            if (item == null) {
                // no value attribute --> create the SelectItem out of the other attributes
                item = SelectItemsUtil.createSelectItem(uiSelectItem, SelectItem::new);
            } else if (!(item instanceof SelectItem)) {
                ValueExpression expression = uiSelectItem.getValueExpression("value");
                throw new IllegalArgumentException("ValueExpression '" + (expression == null ? null : expression.getExpressionString()) + "' of UISelectItem : " + ComponentUtils.getPathToComponent(child) + " does not reference an Object of type SelectItem");
            }
            _nextItem = (SelectItem) item;
            _currentComponent = child;
            _currentValue = item;
            return true;
        } else if (child instanceof UISelectItems) {
            _currentUISelectItems = ((UISelectItems) child);
            Object value = _currentUISelectItems.getValue();
            _currentComponent = child;
            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
                int length = Array.getLength(value);
                Collection<Object> items = new ArrayList<>(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<>(map.size());
                for (Map.Entry<Object, Object> entry : map.entrySet()) {
                    items.add(new SelectItem(entry.getValue(), entry.getKey().toString()));
                }
                _nestedItems = items.iterator();
                return hasNext();
            } else {
                Level level = _facesContext.isProjectStage(ProjectStage.Production) ? Level.FINE : Level.WARNING;
                if (log.isLoggable(level)) {
                    ValueExpression expression = _currentUISelectItems.getValueExpression("value");
                    log.log(level, "ValueExpression {0} of UISelectItems with component-path {1}" + " does not reference an Object of type SelectItem," + " array, Iterable or Map, but of type: {2}", new Object[] { (expression == null ? null : expression.getExpressionString()), ComponentUtils.getPathToComponent(child), (value == null ? null : value.getClass().getName()) });
                }
            }
        } else {
            _currentComponent = null;
            _currentValue = null;
        }
    }
    return false;
}
Also used : UISelectItems(jakarta.faces.component.UISelectItems) UIComponent(jakarta.faces.component.UIComponent) ArrayList(java.util.ArrayList) UISelectItem(jakarta.faces.component.UISelectItem) UISelectItem(jakarta.faces.component.UISelectItem) SelectItem(jakarta.faces.model.SelectItem) ValueExpression(jakarta.el.ValueExpression) Level(java.util.logging.Level) Map(java.util.Map)

Example 5 with SelectItem

use of jakarta.faces.model.SelectItem in project myfaces by apache.

the class SelectItemsUtil method isNoSelectionOption.

/**
 * @param context the faces context
 * @param uiComponent the component instance
 * @param value the value to check
 * @param converter
 * @param iterator contains instances of SelectItem
 * @return if the value is a SelectItem of selectItemsIter, on which noSelectionOption is true
 */
public static boolean isNoSelectionOption(FacesContext context, UIComponent uiComponent, Object value, Iterator<SelectItem> iterator, Converter converter) {
    while (iterator.hasNext()) {
        SelectItem item = iterator.next();
        if (item instanceof SelectItemGroup) {
            SelectItemGroup itemgroup = (SelectItemGroup) item;
            SelectItem[] selectItems = itemgroup.getSelectItems();
            if (selectItems != null && selectItems.length > 0 && isNoSelectionOption(context, uiComponent, value, Arrays.asList(selectItems).iterator(), converter)) {
                return true;
            }
        } else if (item.isNoSelectionOption()) {
            Object itemValue = _convertOrCoerceValue(context, uiComponent, value, item, converter);
            if (value == itemValue || value.equals(itemValue)) {
                return true;
            }
        }
    }
    return false;
}
Also used : UISelectItem(jakarta.faces.component.UISelectItem) SelectItem(jakarta.faces.model.SelectItem) SelectItemGroup(jakarta.faces.model.SelectItemGroup)

Aggregations

SelectItem (jakarta.faces.model.SelectItem)75 ArrayList (java.util.ArrayList)20 UISelectItem (jakarta.faces.component.UISelectItem)17 SelectItemGroup (jakarta.faces.model.SelectItemGroup)17 PrintWriter (java.io.PrintWriter)12 ResponseWriter (jakarta.faces.context.ResponseWriter)11 UISelectItems (jakarta.faces.component.UISelectItems)9 List (java.util.List)9 Converter (jakarta.faces.convert.Converter)7 IOException (java.io.IOException)7 Markup (org.apache.myfaces.tobago.context.Markup)7 TobagoResponseWriter (org.apache.myfaces.tobago.webapp.TobagoResponseWriter)7 ServletException (jakarta.servlet.ServletException)6 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)5 UIComponent (jakarta.faces.component.UIComponent)4 ValueHolder (jakarta.faces.component.ValueHolder)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 SelectItemsIterator (com.sun.faces.renderkit.SelectItemsIterator)2 JSFUtil.handleException (it.vige.rubia.ui.JSFUtil.handleException)2