use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTabRenderer method doRender.
/**
* Paints the given WTab.
*
* @param component the WTab to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTab tab = (WTab) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:tab");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("open", tab.isOpen(), "true");
xml.appendOptionalAttribute("disabled", tab.isDisabled(), "true");
xml.appendOptionalAttribute("hidden", tab.isHidden(), "true");
xml.appendOptionalAttribute("toolTip", tab.getToolTip());
switch(tab.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case SERVER:
xml.appendAttribute("mode", "server");
break;
default:
throw new SystemException("Unknown tab mode: " + tab.getMode());
}
if (tab.getAccessKey() != 0) {
xml.appendAttribute("accessKey", String.valueOf(Character.toUpperCase(tab.getAccessKey())));
}
xml.appendClose();
// Paint label
tab.getTabLabel().paint(renderContext);
// Paint content
WComponent content = tab.getContent();
xml.appendTagOpen("ui:tabcontent");
xml.appendAttribute("id", tab.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
if (content != null && (TabMode.EAGER != tab.getMode() || AjaxHelper.isCurrentAjaxTrigger(tab))) {
// Visibility of content set in prepare paint
content.paint(renderContext);
}
xml.appendEndTag("ui:tabcontent");
xml.appendEndTag("ui:tab");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTableRenderer method paintRows.
/**
* Paints the rows of the table.
*
* @param table the table to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
private void paintRows(final WTable table, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
TableModel model = table.getTableModel();
xml.appendTagOpen("ui:tbody");
xml.appendAttribute("id", table.getId() + ".body");
xml.appendClose();
if (model.getRowCount() == 0) {
xml.appendTag("ui:nodata");
xml.appendEscaped(table.getNoDataMessage());
xml.appendEndTag("ui:nodata");
} else {
// If has at least one visible col, paint the rows.
final int columnCount = table.getColumnCount();
for (int i = 0; i < columnCount; i++) {
if (table.getColumn(i).isVisible()) {
doPaintRows(table, renderContext);
break;
}
}
}
xml.appendEndTag("ui:tbody");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTextAreaRenderer method doRender.
/**
* Paints the given WTextArea.
*
* @param component the WTextArea to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTextArea textArea = (WTextArea) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = textArea.isReadOnly();
xml.appendTagOpen("ui:textarea");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", textArea.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
int cols = textArea.getColumns();
int rows = textArea.getRows();
int minLength = textArea.getMinLength();
int maxLength = textArea.getMaxLength();
WComponent submitControl = textArea.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
xml.appendOptionalAttribute("disabled", textArea.isDisabled(), "true");
xml.appendOptionalAttribute("required", textArea.isMandatory(), "true");
xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
xml.appendOptionalAttribute("toolTip", textArea.getToolTip());
xml.appendOptionalAttribute("accessibleText", textArea.getAccessibleText());
xml.appendOptionalAttribute("rows", rows > 0, rows);
xml.appendOptionalAttribute("cols", cols > 0, cols);
xml.appendOptionalAttribute("buttonId", submitControlId);
xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(textArea));
}
xml.appendClose();
if (textArea.isRichTextArea()) {
/*
* This is a nested element instead of an attribute to cater for future enhancements
* such as turning rich text features on or off, or specifying JSON config either as
* a URL attribute or a nested CDATA section.
*/
xml.append("<ui:rtf />");
}
String textString = textArea.getText();
if (textString != null) {
if (textArea.isReadOnly() && textArea.isRichTextArea()) {
// read only we want to output unescaped, but it must still be XML valid.
xml.write(HtmlToXMLUtil.unescapeToXML(textString));
} else {
xml.appendEscaped(textString);
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(textArea, renderContext);
}
xml.appendEndTag("ui:textarea");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTextFieldRenderer method doRender.
/**
* Paints the given WTextField.
*
* @param component the WTextField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WTextField textField = (WTextField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = textField.isReadOnly();
xml.appendTagOpen("ui:textfield");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
int cols = textField.getColumns();
int minLength = textField.getMinLength();
int maxLength = textField.getMaxLength();
String pattern = textField.getPattern();
WSuggestions suggestions = textField.getSuggestions();
String suggestionsId = suggestions == null ? null : suggestions.getId();
WComponent submitControl = textField.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
xml.appendOptionalAttribute("disabled", textField.isDisabled(), "true");
xml.appendOptionalAttribute("required", textField.isMandatory(), "true");
xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
xml.appendOptionalAttribute("toolTip", textField.getToolTip());
xml.appendOptionalAttribute("accessibleText", textField.getAccessibleText());
xml.appendOptionalAttribute("size", cols > 0, cols);
xml.appendOptionalAttribute("buttonId", submitControlId);
xml.appendOptionalAttribute("pattern", !Util.empty(pattern), pattern);
xml.appendOptionalAttribute("list", suggestionsId);
xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(textField));
}
xml.appendClose();
xml.appendEscaped(textField.getText());
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(textField, renderContext);
}
xml.appendEndTag("ui:textfield");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WTextRenderer method doRender.
/**
* Paints the given WText.
*
* @param component the WText to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WText text = (WText) component;
XmlStringBuilder xml = renderContext.getWriter();
String textString = text.getText();
if (textString != null) {
if (text.isEncodeText()) {
xml.print(WebUtilities.encode(textString));
} else {
// If we are outputting unencoded content it must be XML valid.
xml.print(HtmlToXMLUtil.unescapeToXML(textString));
}
}
}
Aggregations