Search in sources :

Example 1 with SelectItemInfo

use of org.apache.myfaces.renderkit.html.util.SelectItemInfo in project myfaces by apache.

the class HtmlSelectableRendererBase method internalRenderSelect.

protected void internalRenderSelect(FacesContext facesContext, UIComponent uiComponent, boolean disabled, int size, boolean selectMany, Converter converter) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    writer.startElement(HTML.SELECT_ELEM, uiComponent);
    if (uiComponent instanceof ClientBehaviorHolder && !((ClientBehaviorHolder) uiComponent).getClientBehaviors().isEmpty()) {
        writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
    } else {
        HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
    }
    writer.writeAttribute(HTML.NAME_ATTR, uiComponent.getClientId(facesContext), null);
    List<SelectItemInfo> selectItemList;
    if (selectMany) {
        writer.writeAttribute(HTML.MULTIPLE_ATTR, HTML.MULTIPLE_ATTR, null);
        selectItemList = SelectItemsUtils.getSelectItemInfoList((UISelectMany) uiComponent, facesContext);
    } else {
        selectItemList = SelectItemsUtils.getSelectItemInfoList((UISelectOne) uiComponent, facesContext);
    }
    if (size == Integer.MIN_VALUE) {
        // No size given (Listbox) --> size is number of select items
        writer.writeAttribute(HTML.SIZE_ATTR, Integer.toString(selectItemList.size()), null);
    } else {
        writer.writeAttribute(HTML.SIZE_ATTR, Integer.toString(size), null);
    }
    Map<String, List<ClientBehavior>> behaviors = null;
    if (uiComponent instanceof ClientBehaviorHolder) {
        behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
        long commonPropertiesMarked = 0L;
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
        }
        if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderChangeEventProperty(writer, commonPropertiesMarked, uiComponent);
            CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, uiComponent);
            // Note that on JSF 2.3, selectable components don't need onselect attribute
            // Please see https://issues.apache.org/jira/browse/MYFACES-4190
            CommonHtmlAttributesUtil.renderFieldEventPropertiesWithoutOnchangeAndOnselect(writer, commonPropertiesMarked, uiComponent);
        } else {
            HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, behaviors);
            if (isCommonEventsOptimizationEnabled(facesContext)) {
                Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(uiComponent);
                CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
                CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, behaviors);
            } else {
                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
                HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(facesContext, writer, uiComponent, behaviors);
            }
        }
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderSelectPassthroughPropertiesWithoutDisabledAndEvents(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.SELECT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
        }
    } else {
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderSelectPassthroughPropertiesWithoutDisabled(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.SELECT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
        }
    }
    if (disabled) {
        writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
    }
    if (HtmlRendererUtils.isReadOnly(uiComponent)) {
        writer.writeAttribute(HTML.READONLY_ATTR, HTML.READONLY_ATTR, null);
    }
    Set lookupSet = HtmlRendererUtils.getSubmittedOrSelectedValuesAsSet(selectMany, uiComponent, facesContext, converter);
    SelectItemsUtils.renderSelectOptions(facesContext, uiComponent, converter, lookupSet, selectItemList);
    // bug #970747: force separate end tag
    writer.writeText(RendererUtils.EMPTY_STRING, null);
    writer.endElement(HTML.SELECT_ELEM);
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) Set(java.util.Set) ResponseWriter(jakarta.faces.context.ResponseWriter) SelectItemInfo(org.apache.myfaces.renderkit.html.util.SelectItemInfo) List(java.util.List) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder) UISelectOne(jakarta.faces.component.UISelectOne)

Aggregations

UISelectMany (jakarta.faces.component.UISelectMany)1 UISelectOne (jakarta.faces.component.UISelectOne)1 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)1 ResponseWriter (jakarta.faces.context.ResponseWriter)1 List (java.util.List)1 Set (java.util.Set)1 SelectItemInfo (org.apache.myfaces.renderkit.html.util.SelectItemInfo)1