protected void encodeCustomLayout(FacesContext context, SelectManyCheckbox checkbox) throws IOException { List<SelectItem> selectItems = getSelectItems(context, checkbox); Converter converter = checkbox.getConverter(); Object values = getValues(checkbox); Object submittedValues = getSubmittedValues(checkbox); int idx = 0; for (int i = 0; i < selectItems.size(); i++) { SelectItem selectItem = selectItems.get(i); String itemValueAsString = getOptionAsString(context, checkbox, converter, selectItem.getValue()); String name = checkbox.getClientId(context); String id = name + UINamingContainer.getSeparatorChar(context) + idx; Object valuesArray; Object itemValue; if (submittedValues != null) { valuesArray = submittedValues; itemValue = itemValueAsString; } else { valuesArray = values; itemValue = selectItem.getValue(); } boolean selected = isSelected(context, checkbox, itemValue, valuesArray, converter); if (selectItem.isNoSelectionOption() && values != null && !selected) { return; } encodeOptionInput(context, checkbox, id, name, selected, true, itemValueAsString); idx++; } }
if (selectItem.isNoSelectionOption()) { itemStyleClass = itemStyleClass + " ui-noselection-option";
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"); }
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); }
if (option.isNoSelectionOption() && values != null && !selected) { return;
if (option.isNoSelectionOption() && values != null && !selected) { return;
if (option.isNoSelectionOption() && values != null && !selected) { return;
if (option.isNoSelectionOption() && values != null && !checked) { return;
if (option.isNoSelectionOption() && values != null && !selected) { return;
if (option.isNoSelectionOption() && values != null && !selected) { return;
@Override public boolean isNoSelectionOption() { return getSelectItem().isNoSelectionOption(); }
@Override public boolean isNoSelectionOption() { return getSelectItem().isNoSelectionOption(); }
@Override public boolean isNoSelectionOption() { return getSelectItem().isNoSelectionOption(); }
private static void collect(Iterator<SelectItem> items, List<Object> values) { while (items.hasNext()) { SelectItem item = items.next(); if (item instanceof SelectItemGroup) { SelectItem[] subitems = ((SelectItemGroup) item).getSelectItems(); if (!isEmpty(subitems)) { collect(new ArrayIterator(subitems), values); } } else if (!item.isNoSelectionOption()) { values.add(item.getValue()); } } }
private static void collect(Iterator<SelectItem> items, List<Object> values) { while (items.hasNext()) { SelectItem item = items.next(); if (item instanceof SelectItemGroup) { SelectItem[] subitems = ((SelectItemGroup) item).getSelectItems(); if (!isEmpty(subitems)) { collect(new ArrayIterator(subitems), values); } } else if (!item.isNoSelectionOption()) { values.add(item.getValue()); } } }
private static Object findValueByStringConversion(FacesContext context, UIComponent component, Iterator<SelectItem> items, String value, Converter<Object> converter) { while (items.hasNext()) { SelectItem item = items.next(); if (item instanceof SelectItemGroup) { SelectItem[] groupItems = ((SelectItemGroup) item).getSelectItems(); Object object = findValueByStringConversion(context, component, groupItems, value, converter); if (object != null) { return object; } } else if (!item.isNoSelectionOption()) { Object itemValue = item.getValue(); String convertedItemValue = converter.getAsString(context, component, itemValue); if (Objects.equals(value, convertedItemValue)) { return itemValue; } } } return null; }
private static Object findValueByStringConversion(FacesContext context, UIComponent component, Iterator<SelectItem> items, String value, Converter<Object> converter) { while (items.hasNext()) { SelectItem item = items.next(); if (item instanceof SelectItemGroup) { SelectItem[] groupItems = ((SelectItemGroup) item).getSelectItems(); Object object = findValueByStringConversion(context, component, groupItems, value, converter); if (object != null) { return object; } } else if (!item.isNoSelectionOption()) { Object itemValue = item.getValue(); String convertedItemValue = converter.getAsString(context, component, itemValue); if (Objects.equals(value, convertedItemValue)) { return itemValue; } } } return null; }
/** * Parts of this class are an adapted version of InputRenderer#getSelectItems() * of PrimeFaces 5.1. * * @param rw * @throws IOException */ protected void renderOptions(FacesContext context, ResponseWriter rw, SelectOneMenu menu) throws IOException { Converter converter = menu.getConverter(); List<SelectItemAndComponent> items = SelectItemUtils.collectOptions(context, menu, converter); SelectItemAndComponent selection = determineSelectedItem(context, menu, items, converter); for (int index = 0; index < items.size(); index++) { SelectItemAndComponent option = items.get(index); if (option.getSelectItem().isNoSelectionOption() && menu.isHideNoSelectionOption() && selection != null) continue; renderOption(context, menu, rw, (option.getSelectItem()), index, option.getComponent(), option == selection || (selection == null && option.getSelectItem().isNoSelectionOption())); } }
/** * Parts of this class are an adapted version of InputRenderer#getSelectItems() * of PrimeFaces 5.1. * * @param rw * @throws IOException */ protected void renderOptions(FacesContext context, ResponseWriter rw, SelectOneMenu menu) throws IOException { Converter converter = menu.getConverter(); List<SelectItemAndComponent> items = SelectItemUtils.collectOptions(context, menu, converter); SelectItemAndComponent selection = determineSelectedItem(context, menu, items, converter); for (int index = 0; index < items.size(); index++) { SelectItemAndComponent option = items.get(index); if (option.getSelectItem().isNoSelectionOption() && menu.isHideNoSelectionOption() && selection != null) continue; renderOption(context, menu, rw, (option.getSelectItem()), index, option.getComponent(), option == selection || (selection == null && option.getSelectItem().isNoSelectionOption())); } }
private static SelectItem cloneSelectItem(SelectItem o) { SelectItem copy = new SelectItem(); String description = o.getDescription(); if (description != null) copy.setDescription(new String(description)); copy.setDisabled(o.isDisabled()); copy.setEscape(o.isEscape()); String label = o.getLabel(); if (label != null) copy.setLabel(new String(label)); copy.setNoSelectionOption(o.isNoSelectionOption()); copy.setValue(o.getValue()); return copy; } }