in tobago-core/src/main/java/org/apache/myfaces/tobago/internal/util/SelectItemUtils.java [203:284]
public SelectItem next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
if (nextItem != null) {
final 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
final 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 = ComponentUtils.getStringAttribute(currentUISelectItems, Attributes.var);
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 = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemValue);
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
final Object itemLabelObject = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemLabel);
final String itemLabel;
if (itemLabelObject != null) {
itemLabel = itemLabelObject.toString();
} else if (itemValue != null) {
itemLabel = itemValue.toString();
} else {
LOG.warn("Label string can't be created!");
itemLabel = "???";
}
Object itemDescription = ComponentUtils.getAttribute(currentUISelectItems, Attributes.itemDescription);
if (itemDescription != null) {
itemDescription = itemDescription.toString();
}
final boolean itemDisabled
= ComponentUtils.getBooleanAttribute(currentUISelectItems, Attributes.itemDisabled, false);
final String itemImage = ComponentUtils.getStringAttribute(currentUISelectItems, Attributes.itemImage);
final Markup markup;
if (currentUISelectItems instanceof Visual) {
markup = ((Visual) currentUISelectItems).getMarkup();
} else {
markup = Markup.NULL;
}
// TBD: should this be possible?
// Boolean itemLabelEscaped = getBooleanAttribute(currentUISelectItems, ITEM_LABEL_ESCAPED_PROP, true);
// TBD ?
// Object noSelectionValue = attributeMap.get(NO_SELECTION_VALUE_PROP);
item = new org.apache.myfaces.tobago.model.SelectItem(
itemValue, itemLabel, (String) itemDescription, itemDisabled, itemImage, markup);
// remove the value with the key from var from the request map, if previously written
if (wroteRequestMapVarValue) {
// If there was a previous value stored with the key from var in the request map, restore it
if (oldRequestMapVarValue != null) {
facesContext.getExternalContext().getRequestMap().put(var, oldRequestMapVarValue);
} else {
facesContext.getExternalContext().getRequestMap().remove(var);
}
}
}
return (SelectItem) item;
}
throw new NoSuchElementException();
}