Search in sources :

Example 6 with HtmlInputFile

use of jakarta.faces.component.html.HtmlInputFile in project mojarra by eclipse-ee4j.

the class TextRenderer method getEndTextToRender.

// ------------------------------------------------------- Protected Methods
@Override
protected void getEndTextToRender(FacesContext context, UIComponent component, String currentValue) throws IOException {
    ResponseWriter writer = context.getResponseWriter();
    assert writer != null;
    boolean shouldWriteIdAttribute = false;
    boolean isOutput = false;
    String style = (String) component.getAttributes().get("style");
    String styleClass = (String) component.getAttributes().get("styleClass");
    String dir = (String) component.getAttributes().get("dir");
    String lang = (String) component.getAttributes().get("lang");
    String title = (String) component.getAttributes().get("title");
    Map<String, Object> passthroughAttributes = component.getPassThroughAttributes(false);
    boolean hasPassthroughAttributes = null != passthroughAttributes && !passthroughAttributes.isEmpty();
    if (component instanceof UIInput) {
        writer.startElement("input", component);
        writeIdAttributeIfNecessary(context, writer, component);
        if (component instanceof HtmlInputFile) {
            writer.writeAttribute("type", "file", null);
            String accept = ((HtmlInputFile) component).getAccept();
            if (accept != null) {
                writer.writeAttribute("accept", accept, "accept");
            }
        } else if (component instanceof HtmlInputText) {
            String type = ((HtmlInputText) component).getType();
            if (context.isProjectStage(ProjectStage.Development)) {
                String recommendedComponent = RECOMMENDED_COMPONENTS_BY_DISCOMMENDED_TYPES.get(type.trim().toLowerCase());
                if (recommendedComponent != null) {
                    String message = "<h:inputText type=\"" + type + "\"> is discommended, you should instead use " + recommendedComponent;
                    context.addMessage(component.getClientId(context), new FacesMessage(FacesMessage.SEVERITY_WARN, message, message));
                }
            }
            writer.writeAttribute("type", type, null);
        } else {
            writer.writeAttribute("type", "text", null);
        }
        writer.writeAttribute("name", component.getClientId(context), "clientId");
        // as 'on' by the browser
        if ("off".equals(component.getAttributes().get("autocomplete"))) {
            writer.writeAttribute("autocomplete", "off", "autocomplete");
        }
        // render default text specified
        if (currentValue != null) {
            writer.writeAttribute("value", currentValue, "value");
        }
        if (null != styleClass) {
            writer.writeAttribute("class", styleClass, "styleClass");
        }
        // style is rendered as a passthru attribute
        Attribute[] attributes = component instanceof HtmlInputFile ? INPUTFILE_ATTRIBUTES : INPUTTEXT_ATTRIBUTES;
        RenderKitUtils.renderPassThruAttributes(context, writer, component, attributes, getNonOnChangeBehaviors(component));
        RenderKitUtils.renderXHTMLStyleBooleanAttributes(writer, component);
        RenderKitUtils.renderOnchange(context, component, false);
        writer.endElement("input");
    } else if (isOutput = component instanceof UIOutput) {
        if (styleClass != null || style != null || dir != null || lang != null || title != null || hasPassthroughAttributes || (shouldWriteIdAttribute = shouldWriteIdAttribute(component))) {
            writer.startElement("span", component);
            writeIdAttributeIfNecessary(context, writer, component);
            if (null != styleClass) {
                writer.writeAttribute("class", styleClass, "styleClass");
            }
            // style is rendered as a passthru attribute
            RenderKitUtils.renderPassThruAttributes(context, writer, component, OUTPUT_ATTRIBUTES);
        }
        if (currentValue != null) {
            Object val = component.getAttributes().get("escape");
            if (val != null && Boolean.valueOf(val.toString())) {
                writer.writeText(currentValue, component, "value");
            } else {
                writer.write(currentValue);
            }
        }
    }
    if (isOutput && (styleClass != null || style != null || dir != null || lang != null || title != null || hasPassthroughAttributes || shouldWriteIdAttribute)) {
        writer.endElement("span");
    }
}
Also used : ResponseWriter(jakarta.faces.context.ResponseWriter) HtmlInputFile(jakarta.faces.component.html.HtmlInputFile) Attribute(com.sun.faces.renderkit.Attribute) UIOutput(jakarta.faces.component.UIOutput) HtmlInputText(jakarta.faces.component.html.HtmlInputText) UIInput(jakarta.faces.component.UIInput) FacesMessage(jakarta.faces.application.FacesMessage)

Aggregations

HtmlInputFile (jakarta.faces.component.html.HtmlInputFile)6 UIOutput (jakarta.faces.component.UIOutput)3 HtmlInputText (jakarta.faces.component.html.HtmlInputText)3 ArrayList (java.util.ArrayList)3 FacesException (jakarta.faces.FacesException)2 UIComponent (jakarta.faces.component.UIComponent)2 UIForm (jakarta.faces.component.UIForm)2 UIInput (jakarta.faces.component.UIInput)2 UIViewRoot (jakarta.faces.component.UIViewRoot)2 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)2 HtmlBody (jakarta.faces.component.html.HtmlBody)2 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)2 HtmlCommandLink (jakarta.faces.component.html.HtmlCommandLink)2 HtmlGraphicImage (jakarta.faces.component.html.HtmlGraphicImage)2 HtmlHead (jakarta.faces.component.html.HtmlHead)2 HtmlInputHidden (jakarta.faces.component.html.HtmlInputHidden)2 HtmlInputSecret (jakarta.faces.component.html.HtmlInputSecret)2 HtmlInputTextarea (jakarta.faces.component.html.HtmlInputTextarea)2 HtmlOutcomeTargetButton (jakarta.faces.component.html.HtmlOutcomeTargetButton)2 HtmlOutcomeTargetLink (jakarta.faces.component.html.HtmlOutcomeTargetLink)2