Search in sources :

Example 1 with ClientBehaviorHolder

use of jakarta.faces.component.behavior.ClientBehaviorHolder in project myfaces by apache.

the class HtmlGridRendererBase method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
    RendererUtils.checkParamValidity(facesContext, component, UIPanel.class);
    int columns;
    if (component instanceof HtmlPanelGrid) {
        columns = ((HtmlPanelGrid) component).getColumns();
    } else {
        Integer i = (Integer) component.getAttributes().get(ComponentAttrs.COLUMNS_ATTR);
        columns = i != null ? i : 0;
    }
    if (columns <= 0) {
        if (log.isLoggable(Level.SEVERE)) {
            log.severe("Wrong columns attribute for PanelGrid " + component.getClientId(facesContext) + ": " + columns);
        }
        columns = 1;
    }
    ResponseWriter writer = facesContext.getResponseWriter();
    Map<String, List<ClientBehavior>> behaviors = null;
    if (component instanceof ClientBehaviorHolder) {
        behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
    }
    if (behaviors != null && !behaviors.isEmpty()) {
        ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
    }
    writer.startElement(HTML.TABLE_ELEM, component);
    if (component instanceof ClientBehaviorHolder) {
        if (!behaviors.isEmpty()) {
            HtmlRendererUtils.writeIdAndName(writer, component, facesContext);
        } else {
            HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
        }
        long commonPropertiesMarked = 0L;
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(component);
        }
        if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, component);
        } else {
            if (isCommonEventsOptimizationEnabled(facesContext)) {
                CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, CommonHtmlEventsUtil.getMarkedEvents(component), component, behaviors);
            } else {
                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors);
            }
        }
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.TABLE_ATTRIBUTES);
            CommonHtmlAttributesUtil.renderCommonPassthroughPropertiesWithoutEvents(writer, commonPropertiesMarked, component);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.TABLE_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
        }
    } else {
        HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.TABLE_ATTRIBUTES);
            CommonHtmlAttributesUtil.renderCommonPassthroughProperties(writer, CommonHtmlAttributesUtil.getMarkedAttributes(component), component);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.TABLE_PASSTHROUGH_ATTRIBUTES);
        }
    }
    writer.flush();
    HtmlRendererUtils.renderTableCaption(facesContext, writer, component);
    // theader and tfooter are rendered before the tbody
    // Header facet
    renderHeaderOrFooter(facesContext, writer, component, columns, true);
    // Footer facet
    renderHeaderOrFooter(facesContext, writer, component, columns, false);
    renderChildren(facesContext, writer, component, columns);
    writer.endElement(HTML.TABLE_ELEM);
}
Also used : ResponseWriter(jakarta.faces.context.ResponseWriter) List(java.util.List) HtmlPanelGrid(jakarta.faces.component.html.HtmlPanelGrid) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Example 2 with ClientBehaviorHolder

use of jakarta.faces.component.behavior.ClientBehaviorHolder in project myfaces by apache.

the class HtmlImageRendererBase method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
    ResponseWriter writer = facesContext.getResponseWriter();
    Map<String, List<ClientBehavior>> behaviors = null;
    if (uiComponent instanceof ClientBehaviorHolder) {
        behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
        if (!behaviors.isEmpty()) {
            ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
        }
    }
    writer.startElement(HTML.IMG_ELEM, uiComponent);
    if (uiComponent instanceof ClientBehaviorHolder && !behaviors.isEmpty()) {
        HtmlRendererUtils.writeIdAndName(writer, uiComponent, facesContext);
    } else {
        HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
    }
    final String url = RendererUtils.getIconSrc(facesContext, uiComponent, ComponentAttrs.URL_ATTR);
    if (url != null) {
        writer.writeURIAttribute(HTML.SRC_ATTR, url, ComponentAttrs.VALUE_ATTR);
    } else {
        Level level = facesContext.isProjectStage(ProjectStage.Production) ? Level.FINE : Level.WARNING;
        if (log.isLoggable(level)) {
            log.log(level, "Component UIGraphic " + uiComponent.getClientId(facesContext) + " has no attribute url, value, name or attribute resolves to null. Path to component " + ComponentUtils.getPathToComponent(uiComponent));
        }
    }
    /* 
         * Warn the user if the ALT attribute is missing.
         */
    if (uiComponent.getAttributes().get(HTML.ALT_ATTR) == null) {
        Level level = facesContext.isProjectStage(ProjectStage.Production) ? Level.FINE : Level.WARNING;
        if (log.isLoggable(level)) {
            log.log(level, "Component UIGraphic " + uiComponent.getClientId(facesContext) + " has no attribute alt or attribute resolves to null. Path to component " + ComponentUtils.getPathToComponent(uiComponent));
        }
    }
    if (uiComponent instanceof ClientBehaviorHolder) {
        if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderEventProperties(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            if (isCommonEventsOptimizationEnabled(facesContext)) {
                CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), CommonHtmlEventsUtil.getMarkedEvents(uiComponent), uiComponent, behaviors);
            } else {
                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
            }
        }
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_ATTRIBUTES);
            CommonHtmlAttributesUtil.renderCommonPassthroughPropertiesWithoutEvents(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
        }
    } else {
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_ATTRIBUTES);
            CommonHtmlAttributesUtil.renderCommonPassthroughProperties(writer, CommonHtmlAttributesUtil.getMarkedAttributes(uiComponent), uiComponent);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
        }
    }
    writer.endElement(HTML.IMG_ELEM);
}
Also used : ResponseWriter(jakarta.faces.context.ResponseWriter) List(java.util.List) Level(java.util.logging.Level) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Example 3 with ClientBehaviorHolder

use of jakarta.faces.component.behavior.ClientBehaviorHolder in project myfaces by apache.

the class HtmlInputFileRendererBase method decode.

@Override
public void decode(FacesContext facesContext, UIComponent component) {
    try {
        String clientId = component.getClientId();
        HttpServletRequest request = (HttpServletRequest) facesContext.getExternalContext().getRequest();
        Collection<Part> parts = request.getParts();
        Collection<Part> submittedValues = new ArrayList<>(parts.size());
        for (Part part : parts) {
            if (clientId.equals(part.getName())) {
                HttpPartWrapper wrapper = new HttpPartWrapper(part);
                submittedValues.add(wrapper);
            }
        }
        if (((HtmlInputFile) component).isMultiple()) {
            ((UIInput) component).setSubmittedValue(submittedValues);
        } else if (!submittedValues.isEmpty()) {
            ((UIInput) component).setSubmittedValue(submittedValues.iterator().next());
        }
    } catch (IOException | ServletException e) {
        throw new FacesException(e);
    }
    if (component instanceof ClientBehaviorHolder && !HtmlRendererUtils.isDisabled(component)) {
        ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
    }
}
Also used : HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder) UIInput(jakarta.faces.component.UIInput) FacesException(jakarta.faces.FacesException) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) ServletException(jakarta.servlet.ServletException) HttpPartWrapper(org.apache.myfaces.renderkit.html.util.HttpPartWrapper) Part(jakarta.servlet.http.Part)

Example 4 with ClientBehaviorHolder

use of jakarta.faces.component.behavior.ClientBehaviorHolder in project myfaces by apache.

the class HtmlInputFileRendererBase method renderInputBegin.

// Subclasses can set the value of an attribute before, or can render a custom attribute after calling this method
protected void renderInputBegin(FacesContext facesContext, UIComponent component) throws IOException {
    ResponseWriter writer = facesContext.getResponseWriter();
    String clientId = component.getClientId(facesContext);
    writer.startElement(HTML.INPUT_ELEM, component);
    writer.writeAttribute(HTML.ID_ATTR, clientId, null);
    writer.writeAttribute(HTML.NAME_ATTR, clientId, null);
    writer.writeAttribute(HTML.TYPE_ATTR, HTML.INPUT_TYPE_FILE, null);
    Map<String, List<ClientBehavior>> behaviors = null;
    if (component instanceof ClientBehaviorHolder) {
        behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
        long commonPropertiesMarked = 0L;
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            commonPropertiesMarked = CommonHtmlAttributesUtil.getMarkedAttributes(component);
        }
        if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderChangeEventProperty(writer, commonPropertiesMarked, component);
            CommonHtmlAttributesUtil.renderEventProperties(writer, commonPropertiesMarked, component);
            CommonHtmlAttributesUtil.renderFieldEventPropertiesWithoutOnchange(writer, commonPropertiesMarked, component);
        } else {
            HtmlRendererUtils.renderBehaviorizedOnchangeEventHandler(facesContext, writer, component, behaviors);
            if (isCommonEventsOptimizationEnabled(facesContext)) {
                Long commonEventsMarked = CommonHtmlEventsUtil.getMarkedEvents(component);
                CommonHtmlEventsUtil.renderBehaviorizedEventHandlers(facesContext, writer, commonPropertiesMarked, commonEventsMarked, component, behaviors);
                CommonHtmlEventsUtil.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, commonPropertiesMarked, commonEventsMarked, component, behaviors);
            } else {
                HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, behaviors);
                HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchange(facesContext, writer, component, behaviors);
            }
        }
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderInputPassthroughPropertiesWithoutDisabledAndEvents(writer, commonPropertiesMarked, component);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED_AND_EVENTS);
        }
    } else {
        if (isCommonPropertiesOptimizationEnabled(facesContext)) {
            CommonHtmlAttributesUtil.renderInputPassthroughPropertiesWithoutDisabled(writer, CommonHtmlAttributesUtil.getMarkedAttributes(component), component);
        } else {
            HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.INPUT_PASSTHROUGH_ATTRIBUTES_WITHOUT_DISABLED);
        }
    }
    HtmlInputFile inputFile = (HtmlInputFile) component;
    if (inputFile.isDisabled()) {
        writer.writeAttribute(HTML.DISABLED_ATTR, HTML.DISABLED_ATTR, null);
    }
    if (inputFile.isMultiple()) {
        writer.writeAttribute(HTML.MULTIPLE_ATTR, HTML.MULTIPLE_ATTR, null);
    }
    if (AUTOCOMPLETE_VALUE_OFF.equals(inputFile.getAutocomplete())) {
        writer.writeAttribute(HTML.AUTOCOMPLETE_ATTR, AUTOCOMPLETE_VALUE_OFF, HTML.AUTOCOMPLETE_ATTR);
    }
    if (inputFile.getAccept() != null) {
        writer.writeAttribute(HTML.ACCEPT_ATTR, inputFile.getAccept(), HTML.ACCEPT_ATTR);
    }
}
Also used : ResponseWriter(jakarta.faces.context.ResponseWriter) HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) ArrayList(java.util.ArrayList) List(java.util.List) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Example 5 with ClientBehaviorHolder

use of jakarta.faces.component.behavior.ClientBehaviorHolder in project myfaces by apache.

the class HtmlLinkRendererBase method decode.

@Override
public void decode(FacesContext facesContext, UIComponent component) {
    // check for NP
    super.decode(facesContext, component);
    if (component instanceof UICommand) {
        String clientId = component.getClientId(facesContext);
        UIForm form = ComponentUtils.findClosest(UIForm.class, component);
        boolean disabled = HtmlRendererUtils.isDisabled(component);
        // MYFACES-3960 Decode, decode client behavior and queue action event at the end
        boolean activateActionEvent = false;
        if (form != null && !disabled) {
            String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(form, facesContext));
            activateActionEvent = reqValue != null && reqValue.equals(clientId) || HtmlRendererUtils.isPartialOrBehaviorSubmit(facesContext, clientId);
        }
        if (component instanceof ClientBehaviorHolder && !disabled) {
            ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
        }
        if (activateActionEvent) {
            component.queueEvent(new ActionEvent(component));
        }
    } else if (component instanceof UIOutput) {
        // do nothing
        if (component instanceof ClientBehaviorHolder && !HtmlRendererUtils.isDisabled(component)) {
            ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
        }
    } else {
        throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
    }
}
Also used : UIOutput(jakarta.faces.component.UIOutput) ActionEvent(jakarta.faces.event.ActionEvent) UICommand(jakarta.faces.component.UICommand) UIForm(jakarta.faces.component.UIForm) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Aggregations

ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)61 List (java.util.List)38 ResponseWriter (jakarta.faces.context.ResponseWriter)25 ArrayList (java.util.ArrayList)11 UIComponent (jakarta.faces.component.UIComponent)10 AjaxBehavior (jakarta.faces.component.behavior.AjaxBehavior)8 ClientBehavior (jakarta.faces.component.behavior.ClientBehavior)8 UIForm (jakarta.faces.component.UIForm)7 TagException (jakarta.faces.view.facelets.TagException)7 UISelectMany (jakarta.faces.component.UISelectMany)4 FaceletContext (jakarta.faces.view.facelets.FaceletContext)4 UISelectBoolean (jakarta.faces.component.UISelectBoolean)3 UISelectOne (jakarta.faces.component.UISelectOne)3 ClientBehaviorHint (jakarta.faces.component.behavior.ClientBehaviorHint)3 FacesContext (jakarta.faces.context.FacesContext)3 ActionEvent (jakarta.faces.event.ActionEvent)3 TagAttributeException (jakarta.faces.view.facelets.TagAttributeException)3 MessageUtils.getExceptionMessageString (com.sun.faces.util.MessageUtils.getExceptionMessageString)2 ValueExpression (jakarta.el.ValueExpression)2 FacesException (jakarta.faces.FacesException)2