protected SelectItem createSelectItem(FacesContext context, UISelectItems uiSelectItems, Object value, Object label) { String var = (String) uiSelectItems.getAttributes().get("var"); Map<String, Object> attrs = uiSelectItems.getAttributes(); Map<String, Object> requestMap = context.getExternalContext().getRequestMap(); if (var != null) { requestMap.put(var, value); } Object itemLabelValue = attrs.get("itemLabel"); Object itemValue = attrs.get("itemValue"); String description = (String) attrs.get("itemDescription"); Object itemDisabled = attrs.get("itemDisabled"); Object itemEscaped = attrs.get("itemLabelEscaped"); Object noSelection = attrs.get("noSelectionOption"); if (itemValue == null) { itemValue = value; } if (itemLabelValue == null) { itemLabelValue = label; } String itemLabel = itemLabelValue == null ? String.valueOf(value) : String.valueOf(itemLabelValue); boolean disabled = itemDisabled == null ? false : Boolean.parseBoolean(itemDisabled.toString()); boolean escaped = itemEscaped == null ? true : Boolean.parseBoolean(itemEscaped.toString()); boolean noSelectionOption = noSelection == null ? false : Boolean.parseBoolean(noSelection.toString()); if (var != null) { requestMap.remove(var); } return new SelectItem(itemValue, itemLabel, description, disabled, escaped, noSelectionOption); }
protected void encodeOption(FacesContext context, SelectManyMenu menu, SelectItem option, Object values, Object submittedValues, Converter converter) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemValueAsString = getOptionAsString(context, menu, converter, option.getValue()); boolean disabled = option.isDisabled() || menu.isDisabled(); itemValue = option.getValue(); if (option.isNoSelectionOption() && values != null && !selected) { return; writer.startElement("option", null); writer.writeAttribute("value", itemValueAsString, null); if (disabled) { writer.writeAttribute("disabled", "disabled", null); if (option.isEscape()) { writer.writeText(option.getLabel(), null); writer.write(option.getLabel());
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"); }
protected void encodeOptionsAsTable(FacesContext context, SelectOneMenu menu, List<SelectItem> selectItems, List<Column> columns) throws IOException { ResponseWriter writer = context.getResponseWriter(); String var = menu.getVar(); ValueExpression value = menu.getValueExpression("value"); Class<?> valueType = value == null ? null : value.getType(context.getELContext()); Object itemValue = selectItem.getValue(); String itemLabel = selectItem.getLabel(); itemLabel = isValueBlank(itemLabel) ? " " : itemLabel; if (selectItem.isNoSelectionOption()) { itemStyleClass = itemStyleClass + " ui-noselection-option"; context.getExternalContext().getRequestMap().put(var, itemValue); writer.startElement("tr", null); writer.writeAttribute("class", itemStyleClass, null); writer.writeAttribute("data-label", itemLabel, null); if (selectItem.getDescription() != null) { writer.writeAttribute("title", selectItem.getDescription(), null); writer.startElement("td", null); writer.writeAttribute("colspan", columns.size(), null); writer.writeText(selectItem.getLabel(), null); writer.endElement("td"); context.getExternalContext().getRequestMap().put(var, null);
protected void encodeOption(FacesContext context, UIInput component, Object values, Object submittedValues, Converter converter, SelectItem option, int idx) throws IOException { ResponseWriter writer = context.getResponseWriter(); SelectManyCheckbox checkbox = (SelectManyCheckbox) component; String itemValueAsString = getOptionAsString(context, component, converter, option.getValue()); String name = checkbox.getClientId(context); String id = name + UINamingContainer.getSeparatorChar(context) + idx; boolean disabled = option.isDisabled() || checkbox.isDisabled(); Object valuesArray; Object itemValue; if (submittedValues != null) { valuesArray = submittedValues; itemValue = itemValueAsString; } else { valuesArray = values; itemValue = option.getValue(); } boolean selected = isSelected(context, component, itemValue, valuesArray, converter); if (option.isNoSelectionOption() && values != null && !selected) { return; } writer.startElement("div", null); writer.writeAttribute("class", HTML.CHECKBOX_CLASS, null); encodeOptionInput(context, checkbox, id, name, selected, disabled, itemValueAsString); encodeOptionOutput(context, checkbox, selected, disabled); writer.endElement("div"); encodeOptionLabel(context, checkbox, id, option, disabled); }
protected void encodeFilter(FacesContext context, DataTable table, UIColumn column) throws IOException { Map<String, String> params = context.getExternalContext().getRequestParameterMap(); ResponseWriter writer = context.getResponseWriter(); UIComponent filterFacet = column.getFacet("filter"); writer.startElement("label", null); writer.writeAttribute("id", ariaLabelId, null); writer.writeAttribute("for", filterId, null); writer.writeAttribute("class", "ui-helper-hidden", null); writer.writeText(ariaMessage, null); Object itemValue = item.getValue(); writer.startElement("option", null); writer.writeAttribute("value", item.getValue(), null); if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) { writer.writeAttribute("selected", "selected", null); if (item.isEscape()) { writer.writeText(item.getLabel(), "value"); writer.write(item.getLabel()); writer.startElement("div", null); writer.writeAttribute("class", DataTable.COLUMN_CUSTOM_FILTER_CLASS, null); filterFacet.encodeAll(context); writer.endElement("div");
throws IOException { ResponseWriter writer = context.getResponseWriter(); assert(writer != null); RequestStateManager.TARGET_COMPONENT_ATTRIBUTE_NAME, component); Map<String,Object> attributes = component.getAttributes(); OptionComponentInfo optionInfo = new OptionComponentInfo((String) attributes.get("disabledClass"), if (item instanceof SelectItemGroup) { writer.startElement("optgroup", component); writer.writeAttribute("label", item.getLabel(), "label"); Boolean.TRUE.equals(component.getAttributes().get("disabled")); if ((!componentDisabled) && item.isDisabled()) { writer.writeAttribute("disabled", true, "disabled"); ((SelectItemGroup) item).getSelectItems(); for (int i = 0; i < itemsArray.length; ++i) { renderOption(context,
private static void renderSelectOptionsAsText(FacesContext context, UIComponent component, Converter converter, Set lookupSet, List selectItemList, boolean isSelectOne) throws IOException { ResponseWriter writer = context.getResponseWriter(); for (Iterator it = selectItemList.iterator(); it.hasNext();) { SelectItem selectItem = (SelectItem) it.next(); if (selectItem instanceof SelectItemGroup) { SelectItem[] selectItems = ((SelectItemGroup) selectItem) .getSelectItems(); renderSelectOptionsAsText(context, component, converter, lookupSet, Arrays.asList(selectItems), isSelectOne); } else { String itemStrValue = RendererUtils.getConvertedStringValue(context, component, converter, selectItem); if (lookupSet.contains(itemStrValue)) { //TODO/FIX: we always compare the String vales, better fill lookupSet with Strings only when useSubmittedValue==true, else use the real item value Objects if (!isSelectOne) writer.startElement(HTML.LI_ELEM, component); writer.writeText(selectItem.getLabel(), null); if (!isSelectOne) writer.endElement(HTML.LI_ELEM); if (isSelectOne) { //take care of several choices with the same value; use only the first one return; } } } } }
OptionComponentInfo optionInfo) throws IOException { ResponseWriter writer = context.getResponseWriter(); assert (writer != null); Object curValue = curItem.getValue(); boolean checked = isChecked(context, selectOne, curValue); && curItem.isNoSelectionOption() && curValue != null && !checked) { writer.writeText("\t", component, null); writer.startElement("tr", component); writer.writeText("\n", component, null); writer.writeText("\n", component, null); String clientId = component.getClientId(context) + UINamingContainer.getSeparatorChar(context) + Integer.toString(itemNumber); boolean disabled = !optionInfo.isDisabled() && curItem.isDisabled();
public static void encodeItems(FacesContext facesContext, UIComponent component, List<ClientSelectItem> clientSelectItems, String itemHtmlElement, String defaultItemCss) throws IOException { AbstractSelectComponent select = (AbstractSelectComponent) component; if (clientSelectItems != null && !clientSelectItems.isEmpty()) { ResponseWriter writer = facesContext.getResponseWriter(); String clientId = component.getClientId(facesContext); int i = 0; for (ClientSelectItem clientSelectItem : clientSelectItems) { String itemClientId = clientId + "Item" + (i++); clientSelectItem.setClientId(itemClientId); writer.startElement(itemHtmlElement, select); writer.writeAttribute(HtmlConstants.ID_ATTRIBUTE, itemClientId, null); writer.writeAttribute(HtmlConstants.CLASS_ATTRIBUTE, HtmlUtil.concatClasses(defaultItemCss + (clientSelectItem.getSelectItem().isDisabled() ? "-dis" : ""), select.getItemClass()), null); String label = clientSelectItem.getLabel(); if (label != null && label.trim().length() > 0) { writer.writeText(label, null); } else { writer.write("\u00a0"); } writer.endElement(itemHtmlElement); } } }
@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); }
public static void encodeRows(FacesContext facesContext, UIComponent component, SelectManyRendererBase renderer, Iterator<ClientSelectItem> clientSelectItems, String cssPrefix) throws IOException { AbstractSelectManyComponent select = (AbstractSelectManyComponent) component; if (clientSelectItems != null && clientSelectItems.hasNext()) { String clientId = component.getClientId(facesContext); Map<String, Object> requestMap = facesContext.getExternalContext().getRequestMap(); Object oldVar = requestMap.get(select.getVar()); while (clientSelectItems.hasNext()) { ClientSelectItem clientSelectItem = clientSelectItems.next(); requestMap.put(select.getVar(), clientSelectItem.getSelectItem().getValue()); encodeOneRow(facesContext, component, renderer, clientSelectItem, cssPrefix); } requestMap.put(select.getVar(), oldVar); oldVar = null; } }
protected void encodeLineLayout(FacesContext context, SelectOneRadio radio, List<SelectItem> selectItems) throws IOException { ResponseWriter writer = context.getResponseWriter(); Converter converter = radio.getConverter(); String name = radio.getClientId(context); String currentValue = ComponentUtils.getValueToRender(context, radio); writer.startElement("tr", null); for (int i = 0; i < selectItems.size(); i++) { SelectItem selectItem = selectItems.get(i); boolean disabled = selectItem.isDisabled() || radio.isDisabled(); String id = name + UINamingContainer.getSeparatorChar(context) + i; boolean selected = isSelected(context, radio, selectItem, currentValue); writer.startElement("td", null); encodeOption(context, radio, selectItem, id, name, converter, selected, disabled); writer.endElement("td"); } writer.endElement("tr"); }
SelectItem item, boolean disabled) throws IOException { writer.startElement(HTML.LABEL_ELEM, component); writer.writeAttribute(HTML.FOR_ATTR, forClientId, null); labelClass = (String) component.getAttributes().get(JSFAttr.DISABLED_CLASS_ATTR); } else { labelClass = (String) component.getAttributes().get(org.apache.myfaces.shared_impl.renderkit.JSFAttr.ENABLED_CLASS_ATTR); writer.writeAttribute("class", labelClass, "labelClass"); if ((item.getLabel() != null) && (item.getLabel().length() > 0)) { writer.write(" "); if (item.isEscape()) { writer.writeText(item.getLabel(), null); } else { writer.write(item.getLabel());
private String getItemValue(FacesContext facesContext, UISelectItems uiSelectItems, Object item) { String value = null; if (item != null) { if (item instanceof SelectItem) { SelectItem selectItem = (SelectItem) item; Object selectItemValue = selectItem.getValue(); if (selectItemValue != null) { value = selectItemValue.toString(); } } else { Map<String, Object> attributes = uiSelectItems.getAttributes(); String var = (String) attributes.get("var"); if (var != null) { ExternalContext externalContext = facesContext.getExternalContext(); Map<String, Object> requestMap = externalContext.getRequestMap(); requestMap.put(var, item); value = (String) attributes.get("itemValue"); requestMap.remove(var); } else { value = (String) attributes.get("itemValue"); } } } return value; }
protected void encodeLabel(FacesContext context, SelectOneMenu menu, List<SelectItem> selectItems) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("input", null); writer.writeAttribute("type", "text", null); writer.writeAttribute("name", menu.getClientId(context) + "_editableInput", null); writer.writeAttribute("class", SelectOneMenu.LABEL_CLASS, null); for (int i = 0; i < selectItems.size(); i++) { SelectItem selectItem = selectItems.get(i); if (isSelected(context, menu, valueToRender, selectItem.getValue(), null)) { valueToRender = selectItem.getLabel(); break;
public SelectItem[] getListenerIds() { Set ids = listenerRegistry.getListenerIds(); if (ids != null) { SelectItem[] result = new SelectItem[ids.size() + 1]; int i = 1; ResourceBundle rb = ResourceBundle.getBundle("Resource", FacesContext.getCurrentInstance().getExternalContext().getRequestLocale()); result[0] = new SelectItem("", rb.getString("NO_BOUND_LISTENER")); for (Object id : ids) { result[i++] = new SelectItem(id); } return result; } return null; } }
protected void encodeOption(FacesContext context, SelectOneRadio radio, SelectItem option, String id, String name, Converter converter, boolean selected, boolean disabled) throws IOException { ResponseWriter writer = context.getResponseWriter(); String itemValueAsString = getOptionAsString(context, radio, converter, option.getValue()); String styleClass = radio.isPlain() ? HTML.RADIOBUTTON_NATIVE_CLASS : HTML.RADIOBUTTON_CLASS; writer.startElement("div", null); writer.writeAttribute("class", styleClass, null); encodeOptionInput(context, radio, id, name, selected, disabled, itemValueAsString); encodeOptionOutput(context, radio, selected, disabled); writer.endElement("div"); encodeOptionLabel(context, radio, id, option, disabled); }
protected void renderInputElement(FacesContext context, UIComponent htmlSelectManyCheckbox, ResponseWriter writer, String[] selectedValues, final SelectItem selectItem, final boolean disabled) throws IOException { writer.startElement(JsfConstants.INPUT_ELEM, htmlSelectManyCheckbox); RendererUtil.renderAttribute(writer, JsfConstants.TYPE_ATTR, JsfConstants.CHECKBOX_VALUE); RendererUtil.renderAttribute(writer, JsfConstants.NAME_ATTR, htmlSelectManyCheckbox.getClientId(context)); final Object value = selectItem.getValue(); RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, value); renderRemainAttributes(htmlSelectManyCheckbox, writer, ignoreComponent); if (isChecked(selectedValues, value.toString())) { renderCheckedAttribute(writer); } if (disabled) { renderDisabledAttribute(writer); } writer.endElement(JsfConstants.INPUT_ELEM); }
private static <S extends SelectItem> S createSelectItem(UIComponent component, Object value, Supplier<S> supplier) { Map<String, Object> attributes = component.getAttributes(); Object itemValue = getItemValue(attributes, value); Object itemLabel = attributes.get("itemLabel"); Object itemLabelEscaped = coalesce(attributes.get("itemEscaped"), attributes.get("itemLabelEscaped")); // f:selectItem || f:selectItems Object itemDisabled = attributes.get("itemDisabled"); S selectItem = supplier.get(); selectItem.setValue(itemValue); selectItem.setLabel(String.valueOf(itemLabel != null ? itemLabel : selectItem.getValue())); selectItem.setEscape(itemLabelEscaped == null || Boolean.parseBoolean(itemLabelEscaped.toString())); selectItem.setDisabled(itemDisabled != null && Boolean.parseBoolean(itemDisabled.toString())); return selectItem; }