public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
if (!(component instanceof UIInput)) {
LOG.error("Wrong type: Need " + UIInput.class.getName() + ", but was " + component.getClass().getName());
return;
}
UIInput input = (UIInput) component;
String title = HtmlRendererUtil.getTitleFromTipAndMessages(facesContext, input);
final boolean password = ComponentUtil.getBooleanAttribute(input, ATTR_PASSWORD);
String currentValue = getCurrentValue(facesContext, input);
if (LOG.isDebugEnabled()) {
LOG.debug("currentValue = '"
+ (password && currentValue != null ? StringUtils.leftPad("", currentValue.length(), '*') : currentValue)
+ "'");
}
String type = password ? "password" : "text";
// Todo: check for valid binding
boolean renderAjaxSuggest = input.getSuggestMethod() != null;
String id = input.getClientId(facesContext);
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlConstants.INPUT, input);
writer.writeAttribute(HtmlAttributes.TYPE, type, false);
writer.writeNameAttribute(id);
writer.writeIdAttribute(id);
if (currentValue != null) {
writer.writeAttribute(HtmlAttributes.VALUE, currentValue, true);
}
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
int maxLength = 0;
for (Validator validator : input.getValidators()) {
if (validator instanceof LengthValidator) {
LengthValidator lengthValidator = (LengthValidator) validator;
maxLength = lengthValidator.getMaximum();
}
}
if (maxLength > 0) {
writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
}
writer.writeAttribute(HtmlAttributes.READONLY, ComponentUtil.getBooleanAttribute(input, ATTR_READONLY));
writer.writeAttribute(HtmlAttributes.DISABLED, ComponentUtil.getBooleanAttribute(input, ATTR_DISABLED));
Integer tabIndex = input.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
writer.writeStyleAttribute();