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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations