if (!(component instanceof UITextarea)) {
LOG.error("Wrong type: Need " + UITextarea.class.getName() + ", but was " + component.getClass().getName());
return;
}
UITextarea input = (UITextarea) component;
String title = HtmlRendererUtils.getTitleFromTipAndMessages(facesContext, component);
String clientId = input.getClientId(facesContext);
String onchange = HtmlUtils.generateOnchange(input, facesContext);
TobagoResponseWriter writer = HtmlRendererUtils.getTobagoResponseWriter(facesContext);
writer.startElement(HtmlElements.TEXTAREA, input);
writer.writeNameAttribute(clientId);
writer.writeIdAttribute(clientId);
writer.writeAttribute(HtmlAttributes.ROWS, null, Attributes.ROWS);
if (title != null) {
writer.writeAttribute(HtmlAttributes.TITLE, title, true);
}
writer.writeAttribute(HtmlAttributes.READONLY, input.isReadonly());
writer.writeAttribute(HtmlAttributes.DISABLED, input.isDisabled());
Integer tabIndex = input.getTabIndex();
if (tabIndex != null) {
writer.writeAttribute(HtmlAttributes.TABINDEX, tabIndex);
}
HtmlRendererUtils.renderDojoDndItem(component, writer, true);
writer.writeClassAttribute(Classes.create(input));
Style style = new Style(facesContext, input);
writer.writeStyleAttribute(style);
if (onchange != null) {
writer.writeAttribute(HtmlAttributes.ONCHANGE, onchange, null);
}
/*int maxLength = -1;
for (Validator validator : input.getValidators()) {
if (validator instanceof LengthValidator) {
LengthValidator lengthValidator = (LengthValidator) validator;
maxLength = lengthValidator.getMaximum();
}
}
if (maxLength > 0) {
writer.writeAttribute(HtmlAttributes.MAXLENGTH, maxLength);
}
String placeholder = input.getPlaceholder();
if (placeholder != null) {
writer.writeAttribute(HtmlAttributes.PLACEHOLDER, placeholder, true);
}*/
String currentValue = RenderUtils.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(HtmlElements.TEXTAREA);
/*if (placeholder != null && !VariableResolverUtils.resolveClientProperties(facesContext)
.getUserAgent().hasCapability(Capability.PLACEHOLDER)) {
HtmlRendererUtils.createPlaceholderDiv(input, currentValue, placeholder, style, writer);
}*/
HtmlRendererUtils.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 = ComponentUtils.getBooleanAttribute(input, Attributes.REQUIRED);
if (required || maxLength > 0) {
final String[] cmds = {
"new Tobago.In(\"" + input.getClientId(facesContext) + "\"," + required + ",\""
+ Classes.requiredWorkaround(input) + "\" " + (maxLength > -1 ? "," + maxLength : "") + " );"
};
HtmlRendererUtils.writeScriptLoader(facesContext, null, cmds);
}