Search in sources :

Example 1 with UISelectBoolean

use of jakarta.faces.component.UISelectBoolean in project myfaces by apache.

the class HtmlCheckboxRendererBase method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    if (uiComponent instanceof UISelectBoolean) {
        ResponseWriter writer = facesContext.getResponseWriter();
        writer.endElement(HTML.INPUT_ELEM);
    } else if (uiComponent instanceof UISelectMany) {
        renderCheckboxList(facesContext, (UISelectMany) uiComponent);
    } else {
        throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
    }
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) ResponseWriter(jakarta.faces.context.ResponseWriter) UISelectBoolean(jakarta.faces.component.UISelectBoolean)

Example 2 with UISelectBoolean

use of jakarta.faces.component.UISelectBoolean in project myfaces by apache.

the class HtmlCheckboxRendererBase method encodeBegin.

@Override
public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    RendererUtils.checkParamValidity(facesContext, uiComponent, null);
    if (uiComponent instanceof ClientBehaviorHolder) {
        Map<String, List<ClientBehavior>> behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
        if (!behaviors.isEmpty()) {
            ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, facesContext.getResponseWriter());
        }
    }
    if (uiComponent instanceof UISelectBoolean) {
        Boolean value = RendererUtils.getBooleanValue(uiComponent);
        boolean isChecked = value != null ? value : false;
        renderCheckbox(facesContext, uiComponent, EXTERNAL_TRUE_VALUE, false, isChecked, true, null);
    // TODO: the selectBoolean is never disabled
    } else if (uiComponent instanceof UISelectMany) {
        // let the current impl do what it does in encodeEnd do nothing here just don't want exception
        // throw if it is this case
        log.finest("encodeBegin() doing nothing intentionally for UISelectMany");
    } else {
        throw new IllegalArgumentException("Unsupported component class " + uiComponent.getClass().getName());
    }
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) List(java.util.List) UISelectBoolean(jakarta.faces.component.UISelectBoolean) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder) UISelectBoolean(jakarta.faces.component.UISelectBoolean)

Example 3 with UISelectBoolean

use of jakarta.faces.component.UISelectBoolean in project myfaces by apache.

the class HtmlCheckboxRendererBase method renderCheckbox.

/**
 * Renders the input item
 * @return the 'id' value of the rendered element
 */
protected String renderCheckbox(FacesContext facesContext, UIComponent uiComponent, String value, boolean disabled, boolean checked, boolean renderId, Integer itemNum) throws IOException {
    String clientId = uiComponent.getClientId(facesContext);
    String itemId = (itemNum == null) ? null : clientId + facesContext.getNamingContainerSeparatorChar() + itemNum;
    ResponseWriter writer = facesContext.getResponseWriter();
    writer.startElement(HTML.INPUT_ELEM, uiComponent);
    if (itemId != null) {
        writer.writeAttribute(HTML.ID_ATTR, itemId, null);
    } else if (renderId) {
        writer.writeAttribute(HTML.ID_ATTR, clientId, null);
    }
    writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_CHECKBOX, null);
    writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
    if (checked) {
        writer.writeAttribute(HTML.CHECKED_ATTR, HTML.CHECKED_ATTR, null);
    }
    if (disabled) {
        writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
    }
    if ((value != null) && (value.length() > 0)) {
        writer.writeAttribute(HTML.VALUE_ATTR, value, null);
    }
    Map<String, List<ClientBehavior>> behaviors = null;
    if (uiComponent instanceof UISelectBoolean) {
        if (uiComponent instanceof ClientBehaviorHolder) {
            behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
            if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
                long commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
                CommonHtmlAttributesUtil.renderChangeEventProperty(writer, commonPropertiesMarked, uiComponent);
                CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, uiComponent);
                CommonHtmlAttributesUtil.renderFieldEventPropertiesWithoutOnchange(writer, commonPropertiesMarked, uiComponent);
            } else {
                long commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
                HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
                if (isCommonEventsOptimizationEnabled(facesContext)) {
                    Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(uiComponent);
                    CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
                    CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
                } else {
                    HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
                    HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
                }
            }
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
        }
    } else {
        if (uiComponent instanceof ClientBehaviorHolder) {
            behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
            if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
                long commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
                CommonHtmlAttributesUtil.renderChangeEventProperty(writer, commonPropertiesMarked, uiComponent);
                CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, uiComponent);
                CommonHtmlAttributesUtil.renderFieldEventPropertiesWithoutOnchange(writer, commonPropertiesMarked, uiComponent);
            } else {
                long commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent);
                HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
                if (isCommonEventsOptimizationEnabled(facesContext)) {
                    Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(uiComponent);
                    CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
                    CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, commonPropertiesMarked, commonEventsMarked, uiComponent, itemId != null ? itemId : clientId, behaviors);
                } else {
                    HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
                    HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, uiComponent, itemId != null ? itemId : clientId, behaviors);
                }
            }
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE_AND_EVENTS);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_STYLE);
        }
    }
    if (isDisabled(facesContext, uiComponent)) {
        writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
    }
    if (uiComponent instanceof UISelectMany) {
        writer.endElement(HTML.INPUT_ELEM);
    }
    return itemId;
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) ResponseWriter(jakarta.faces.context.ResponseWriter) List(java.util.List) UISelectBoolean(jakarta.faces.component.UISelectBoolean) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Example 4 with UISelectBoolean

use of jakarta.faces.component.UISelectBoolean in project faces by jakartaee.

the class TestServlet method uiComponentGetSetValueExpressionTest.

// ------------------------------------------- Test Methods ----
@Override
public void uiComponentGetSetValueExpressionTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
    super.uiComponentGetSetValueExpressionTest(request, wrapper);
    String result = wrapper.getBufferedWriter().toString();
    PrintWriter out = response.getWriter();
    if (result.indexOf(JSFTestUtil.PASS) == -1) {
        out.println(result);
        return;
    }
    // default processing of get,setValueExpression is ok, now validate
    // processing specific to UIGraphic
    request.setAttribute("value", "selectedValue");
    ExpressionFactory factory = JSFTestUtil.getExpressionFactory(servletContext);
    ValueExpression expression = factory.createValueExpression(getFacesContext().getELContext(), "#{requestScope.value}", java.lang.String.class);
    UISelectBoolean selBoolean = (UISelectBoolean) createComponent();
    selBoolean.setValueExpression("selected", expression);
    if (!"selectedValue".equals(selBoolean.getValue())) {
        out.println(JSFTestUtil.FAIL + " setValueExpression() with a key of 'selected'" + " didn't set the ValueExpression provided as the value" + " of the component.");
        out.println("Expected: " + expression);
        out.println("Received: " + selBoolean.getValue());
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) UISelectBoolean(jakarta.faces.component.UISelectBoolean) BufferedResponseWrapper(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper) PrintWriter(java.io.PrintWriter)

Example 5 with UISelectBoolean

use of jakarta.faces.component.UISelectBoolean in project myfaces by apache.

the class HtmlRendererUtils method renderDisplayValueOnlyForSelects.

public static void renderDisplayValueOnlyForSelects(FacesContext facesContext, UIComponent uiComponent, boolean considerValueType) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    List selectItemList = null;
    Converter converter = null;
    boolean isSelectOne = false;
    if (uiComponent instanceof UISelectBoolean) {
        converter = findUIOutputConverterFailSafe(facesContext, uiComponent);
        writer.startElement(HTML.SPAN_ELEM, uiComponent);
        writeIdIfNecessary(writer, uiComponent, facesContext);
        writer.writeText(RendererUtils.getConvertedStringValue(facesContext, uiComponent, converter, ((UISelectBoolean) uiComponent).getValue()), ComponentAttrs.VALUE_ATTR);
        writer.endElement(HTML.SPAN_ELEM);
    } else {
        if (uiComponent instanceof UISelectMany) {
            isSelectOne = false;
            selectItemList = RendererUtils.getSelectItemList((UISelectMany) uiComponent, facesContext);
            converter = findUISelectManyConverterFailsafe(facesContext, uiComponent, considerValueType);
        } else if (uiComponent instanceof UISelectOne) {
            isSelectOne = true;
            selectItemList = RendererUtils.getSelectItemList((UISelectOne) uiComponent, facesContext);
            converter = findUIOutputConverterFailSafe(facesContext, uiComponent);
        }
        writer.startElement(isSelectOne ? HTML.SPAN_ELEM : HTML.UL_ELEM, uiComponent);
        writeIdIfNecessary(writer, uiComponent, facesContext);
        Set lookupSet = getSubmittedOrSelectedValuesAsSet(uiComponent instanceof UISelectMany, uiComponent, facesContext, converter);
        renderSelectOptionsAsText(facesContext, uiComponent, converter, lookupSet, selectItemList, isSelectOne);
        // bug #970747: force separate end tag
        writer.writeText(RendererUtils.EMPTY_STRING, null);
        writer.endElement(isSelectOne ? HTML.SPAN_ELEM : HTML.UL_ELEM);
    }
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) Set(java.util.Set) ResponseWriter(jakarta.faces.context.ResponseWriter) Converter(jakarta.faces.convert.Converter) List(java.util.List) UISelectBoolean(jakarta.faces.component.UISelectBoolean) UISelectOne(jakarta.faces.component.UISelectOne)

Aggregations

UISelectBoolean (jakarta.faces.component.UISelectBoolean)6 UISelectMany (jakarta.faces.component.UISelectMany)4 ResponseWriter (jakarta.faces.context.ResponseWriter)3 List (java.util.List)3 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)2 PrintWriter (java.io.PrintWriter)2 BufferedResponseWrapper (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper)1 ExpressionFactory (jakarta.el.ExpressionFactory)1 ValueExpression (jakarta.el.ValueExpression)1 UISelectOne (jakarta.faces.component.UISelectOne)1 Converter (jakarta.faces.convert.Converter)1 Set (java.util.Set)1