All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.butterfaces.component.partrenderer.MaxLengthPartRenderer Maven / Gradle / Ivy

There is a newer version: 3.5.0
Show newest version
package org.butterfaces.component.partrenderer;

import java.io.IOException;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import org.butterfaces.component.html.HtmlInputComponent;
import org.butterfaces.component.html.feature.MaxLength;
import org.butterfaces.resolver.WebXmlParameters;

public class MaxLengthPartRenderer {

    public void renderMaxLength(final HtmlInputComponent component, final ResponseWriter writer) throws IOException {
        final UIInput uiComponent = (UIInput) component;
        final String outerComponentId = component.getClientId();

        if (isMaxLengthNecessary(component)) {
            final String maxLengthText = new WebXmlParameters(FacesContext.getCurrentInstance().getExternalContext()).getMaxLengthText();
            final Integer maxLength = ((MaxLength) component).getMaxLength();

            RenderUtils
                .renderJQueryPluginCall(outerComponentId, "butterMaxLength({maxLength: " + maxLength + ", maxLengthText: '" + maxLengthText + "'})", writer, uiComponent);
        }
    }

    private boolean isMaxLengthNecessary(final HtmlInputComponent component) {
        return component instanceof MaxLength && ((MaxLength) component).getMaxLength() != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy