}
@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
final AbstractUIInput input = (AbstractUIInput) component;
final String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, input);
final String currentValue = getCurrentValue(facesContext, input);
final boolean password = ComponentUtils.getBooleanAttribute(input, Attributes.PASSWORD);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '"
+ (password && currentValue != null ? StringUtils.leftPad("", currentValue.length(), '*') : currentValue)
+ "'");
}
final String type = password ? HtmlInputTypes.PASSWORD : HtmlInputTypes.TEXT;
final String id = input.getClientId(facesContext);
final boolean readonly = input.isReadonly();
final boolean disabled = input.isDisabled();
final TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.INPUT, input);
writer.writeAttribute(HtmlAttributes.TYPE, type, false);
writer.writeNameAttribute(id);
writer.writeIdAttribute(id);
HtmlRendererUtils.writeDataAttributes(facesContext, writer, input);
if (currentValue != null) {
writer.writeAttribute(HtmlAttributes.VALUE, currentValue, true);
}
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
int maxLength = 0;
String pattern = null;
for (Validator validator : input.getValidators()) {
if (validator instanceof LengthValidator) {
LengthValidator lengthValidator = (LengthValidator) validator;
maxLength = lengthValidator.getMaximum();
}
/*if (validator instanceof RegexValidator) {
RegexValidator regexValidator = (RegexValidator) validator;
pattern = regexValidator.getPattern();
}*/
}
if (maxLength > 0) {
writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
}
if (pattern != null) {
writer.writeAttribute(HtmlAttributes.PATTERN, pattern, false);
}
writer.writeAttribute(HtmlAttributes.READONLY, readonly);
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
Integer tabIndex = input.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
Style style = new Style(facesContext, input);
writer.writeStyleAttribute(style);
final String placeholder = input.getPlaceholder();
if (!disabled && !readonly && StringUtils.isNotBlank(placeholder)) {
writer.writeAttribute(HtmlAttributes.PLACEHOLDER, placeholder, true);
}
if (input instanceof AbstractUIIn && ((AbstractUIIn) input).getSuggest() != null) {
writer.writeAttribute(HtmlAttributes.AUTOCOMPLETE, "off", false);
}
HtmlRendererUtils.renderDojoDndItem(component, writer, true);
writer.writeClassAttribute(Classes.create(input));
/*if (component instanceof AbstractUIInput) {
String onchange = HtmlUtils.generateOnchange((AbstractUIInput) component, facesContext);
if (onchange != null) {
// TODO: create and use utility method to write attributes without quoting
// writer.writeAttribute(HtmlAttributes.ONCHANGE, onchange, null);
}
} */
boolean required = ComponentUtils.getBooleanAttribute(input, Attributes.REQUIRED);
writer.writeAttribute(HtmlAttributes.REQUIRED, required);
HtmlRendererUtils.renderFocus(id, input.isFocus(), ComponentUtils.isError(input), facesContext, writer);
writeAdditionalAttributes(facesContext, writer, input);
HtmlRendererUtils.renderCommandFacet(input, facesContext, writer);
writer.endElement(HtmlElements.INPUT);
}