@Override public void decode(FacesContext context, UIComponent component) { SelectOneMenu menu = (SelectOneMenu) component; if (!shouldDecode(menu)) { return; } if (!menu.isEditable()) { super.decode(context, component); return; } decodeBehaviors(context, menu); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); // default to user entered input String editableInputId = menu.getClientId(context) + "_editableInput"; if (!params.containsKey(editableInputId)) { return; } String submittedValue = params.get(editableInputId); // #2862 check if it matches a label and if so use the value SelectItem match = null; for (SelectItem item : getSelectItems(context, menu)) { if (item.getLabel().equalsIgnoreCase(submittedValue)) { match = item; break; } } menu.setSubmittedValue(match != null ? getOptionAsString(context, menu, menu.getConverter(), match.getValue()) : submittedValue); }
protected void encodeOptionLabel(FacesContext context, SelectManyCheckbox checkbox, String containerClientId, SelectItem option, boolean disabled) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("label", null); if (disabled) { writer.writeAttribute("class", "ui-state-disabled", null); } writer.writeAttribute("for", containerClientId, null); if (option.getDescription() != null) { writer.writeAttribute("title", option.getDescription(), null); } if (option.isEscape()) { writer.writeText(option.getLabel(), null); } else { writer.write(option.getLabel()); } writer.endElement("label"); }
SelectItem selectItem = selectItems.get(i); Object itemValue = selectItem.getValue(); String itemLabel = selectItem.getLabel(); itemLabel = isValueBlank(itemLabel) ? " " : itemLabel; writer.startElement("td", null); writer.writeAttribute("colspan", columns.size(), null); writer.writeText(selectItem.getLabel(), null); writer.endElement("td");
protected void encodeListItems(FacesContext context, MultiSelectListbox listbox, SelectItem[] selectItems) throws IOException { if (selectItems != null && selectItems.length > 0) { ResponseWriter writer = context.getResponseWriter(); Converter converter = ComponentUtils.getConverter(context, listbox); String itemValue = null; for (int i = 0; i < selectItems.length; i++) { SelectItem selectItem = selectItems[i]; itemValue = converter != null ? converter.getAsString(context, listbox, selectItem.getValue()) : String.valueOf(selectItem.getValue()); writer.startElement("li", null); writer.writeAttribute("class", MultiSelectListbox.ITEM_CLASS, null); writer.writeAttribute("data-value", itemValue, null); writer.startElement("span", listbox); writer.writeText(selectItem.getLabel(), null); writer.endElement("span"); if (selectItem instanceof SelectItemGroup) { SelectItemGroup group = (SelectItemGroup) selectItem; SelectItem[] groupItems = group.getSelectItems(); if (groupItems != null && groupItems.length > 0) { encodeGroupItems(context, listbox, group.getSelectItems()); } } writer.endElement("li"); } } }
protected void encodeOptionLabel(FacesContext context, SelectOneRadio radio, String containerClientId, SelectItem option, boolean disabled) throws IOException { ResponseWriter writer = context.getResponseWriter(); String label = option.getLabel(); writer.startElement("label", null); writer.writeAttribute("for", containerClientId, null); if (disabled) { writer.writeAttribute("class", "ui-state-disabled", null); } if (option.getDescription() != null) { writer.writeAttribute("title", option.getDescription(), null); } if (label != null) { if (option.isEscape()) { writer.writeText(label, null); } else { writer.write(label); } } writer.endElement("label"); }
protected void encodeItem(FacesContext context, SelectOneMenu menu, SelectItem selectItem, String styleClass) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemLabel = selectItem.getLabel(); itemLabel = isValueBlank(itemLabel) ? " " : itemLabel; String itemStyleClass = styleClass; if (selectItem.isNoSelectionOption()) { itemStyleClass = itemStyleClass + " ui-noselection-option"; } writer.startElement("li", null); writer.writeAttribute("class", itemStyleClass, null); writer.writeAttribute("data-label", itemLabel, null); writer.writeAttribute("tabindex", "-1", null); writer.writeAttribute("role", "option", null); if (selectItem.getDescription() != null) { writer.writeAttribute("title", selectItem.getDescription(), null); } if (itemLabel.equals(" ")) { writer.write(itemLabel); } else { if (selectItem.isEscape()) { writer.writeText(itemLabel, "value"); } else { writer.write(itemLabel); } } writer.endElement("li"); }
boolean disabled = option.isDisabled() || menu.isDisabled(); boolean escaped = option.isEscape(); String itemLabel = option.getLabel(); itemLabel = isValueBlank(itemLabel) ? " " : itemLabel;
SelectItem selectItem = selectItems.get(i); if (isSelected(context, menu, valueToRender, selectItem.getValue(), null)) { valueToRender = selectItem.getLabel(); break;
private static void unitTestSelectItemList(List list) { for (Iterator iter = list.iterator(); iter.hasNext(); ) { SelectItem item = (SelectItem)iter.next(); log.debug("item.getLabel()={}", item.getLabel()); log.debug("item.getValue()={}", item.getValue()); } }
protected void addSelectItemValue(StringBuilder builder, SelectItem item) throws IOException { String value; if (item == null) value = ""; else { if ("value".equalsIgnoreCase(textToExport)) value = (String) item.getValue(); else if ("both".equalsIgnoreCase(textToExport)) value = item.getLabel() + "(" + item.getValue() + ")"; else value = item.getLabel(); } value = value == null ? "" : value.trim(); builder.append(encloseInCDATASection(value)); }
public static ClientSelectItem generateClientSelectItem(FacesContext facesContext, UIComponent component, SelectItem selectItem, int sortOrder, boolean selected) { String convertedStringValue = InputUtils.getConvertedStringValue(facesContext, component, selectItem.getValue()); String label = selectItem.getLabel(); ClientSelectItem clientSelectItem = new ClientSelectItem(selectItem, convertedStringValue, label, sortOrder, selected); return clientSelectItem; }