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, component);
String clientId = input.getClientId(facesContext);
String onchange = HtmlUtils.generateOnchange(input, facesContext);
TobagoResponseWriter writer = HtmlRendererUtil.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlConstants.TEXTAREA, input);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
writer.writeAttribute(HtmlAttributes.ROWS, null, ATTR_ROWS);
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
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();
writer.writeClassAttribute();
if (onchange != null) {
writer.writeAttribute(HtmlAttributes.ONCHANGE, onchange, null);
}
String currentValue = ComponentUtil.currentValue(input);
if (currentValue != null) {
// this is because browsers eat the first CR+LF of <textarea>
if (currentValue.startsWith("\r\n")) {
currentValue = "\r\n" + currentValue;
} else if (currentValue.startsWith("\n")) {
currentValue = "\n" + currentValue;
} else if (currentValue.startsWith("\r")) {
currentValue = "\r" + currentValue;
}
writer.writeText(currentValue, null);
}
writer.endElement(HtmlConstants.TEXTAREA);
checkForCommandFacet(input, facesContext, writer);
int maxLength = -1;
for (Validator validator : input.getValidators()) {
if (validator instanceof LengthValidator) {
LengthValidator lengthValidator = (LengthValidator) validator;
maxLength = lengthValidator.getMaximum();
}
}
boolean required = ComponentUtil.getBooleanAttribute(input, TobagoConstants.ATTR_REQUIRED);
if (required || maxLength > 0) {
String rendererName = HtmlRendererUtil.getRendererName(facesContext, input);
final String[] cmds = {
"new Tobago.In(\"" + input.getClientId(facesContext) + "\", true ,\""
+ StyleClasses.PREFIX + rendererName + "\" " + (maxLength > -1? "," + maxLength: "") + " );"
};
HtmlRendererUtil.writeScriptLoader(facesContext, null, cmds);
}