private int getSize(UIComponent component) { int size = UIComponentUtil.getPrimitiveIntAttribute(component, JsfConstants.SIZE_ATTR); if (0 < size) { return size; } size = 0; for (Iterator it = new SelectItemsIterator(component); it.hasNext(); ) { SelectItem item = (SelectItem) it.next(); if (item instanceof SelectItemGroup) { SelectItemGroup itemGroup = (SelectItemGroup) item; size += itemGroup.getSelectItems().length; } size++; } return size; }
protected void renderSelectItems( FacesContext context, UIComponent component, ResponseWriter writer, Iterator it, String[] selectedValues) throws IOException { while (it.hasNext()) { final SelectItem selectItem = (SelectItem) it.next(); if (selectItem instanceof SelectItemGroup) { SelectItemGroup selectItemGroup = (SelectItemGroup) selectItem; SelectItem[] selectItems = selectItemGroup.getSelectItems(); Iterator selectItemsIt = new ArrayIterator(selectItems); writer.startElement(JsfConstants.OPTGROUP_ELEM, component); RendererUtil.renderAttribute(writer, JsfConstants.LABEL_ATTR, selectItemGroup.getLabel()); // TODO case: optgroup is disabled renderSelectItems(context, component, writer, selectItemsIt, selectedValues); writer.endElement(JsfConstants.OPTGROUP_ELEM); } else { writer.startElement(JsfConstants.OPTION_ELEM, component); final Object value = selectItem.getValue(); RendererUtil.renderAttribute(writer, JsfConstants.VALUE_ATTR, value); final boolean disabled = UIComponentUtil.isDisabled(component) || selectItem.isDisabled(); final String labelClass = getLabelStyleClass(component, disabled); if (labelClass != null) { RendererUtil.renderAttribute(writer, JsfConstants.CLASS_ATTR, labelClass); } if (value != null && isSelected(selectedValues, value.toString())) { renderSelectedAttribute(writer); } if (selectItem.isDisabled()) { renderDisabledAttribute(writer); } writer.writeText(selectItem.getLabel(), null); writer.endElement(JsfConstants.OPTION_ELEM); } } }
public static Object getConvertedValue( final FacesContext context, final UIInput component, final Object submittedValue) { try { final Renderer renderer = getRenderer(context, component); if (renderer != null) { return renderer.getConvertedValue(context, component, submittedValue); } else if (submittedValue instanceof String) { return getConvertedUIOutputValue(context, component, submittedValue); } } catch (final ConverterException e) { final FacesMessage facesMessage = e.getFacesMessage(); if (facesMessage != null) { context.addMessage(component.getClientId(context), facesMessage); } else { final Object[] args = new Object[] {UIComponentUtil.getLabel(component)}; context.addMessage( component.getClientId(context), FacesMessageUtil.getMessage(context, UIInput.CONVERSION_MESSAGE_ID, args)); } component.setValid(false); } return submittedValue; }