use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WMultiSelectRenderer method doRender.
/**
* Paints the given WMultiSelect.
*
* @param component the WMultiSelect to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMultiSelect listBox = (WMultiSelect) component;
XmlStringBuilder xml = renderContext.getWriter();
String dataKey = listBox.getListCacheKey();
boolean readOnly = listBox.isReadOnly();
int rows = listBox.getRows();
int min = listBox.getMinSelect();
int max = listBox.getMaxSelect();
xml.appendTagOpen("ui:listbox");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", listBox.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("data", dataKey != null && !readOnly, dataKey);
xml.appendOptionalAttribute("disabled", listBox.isDisabled(), "true");
xml.appendOptionalAttribute("required", listBox.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", listBox.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", component.getToolTip());
xml.appendOptionalAttribute("accessibleText", component.getAccessibleText());
xml.appendOptionalAttribute("rows", rows >= 2, rows);
xml.appendOptionalAttribute("min", min > 0, min);
xml.appendOptionalAttribute("max", max > 0, max);
}
xml.appendClose();
// Options
List<?> options = listBox.getOptions();
boolean renderSelectionsOnly = readOnly || dataKey != null;
if (options != null) {
int optionIndex = 0;
List<?> selections = listBox.getSelected();
for (Object option : options) {
if (option instanceof OptionGroup) {
xml.appendTagOpen("ui:optgroup");
xml.appendAttribute("label", ((OptionGroup) option).getDesc());
xml.appendClose();
for (Object nestedOption : ((OptionGroup) option).getOptions()) {
renderOption(listBox, nestedOption, optionIndex++, xml, selections, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(listBox, option, optionIndex++, xml, selections, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
}
xml.appendEndTag("ui:listbox");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WNumberFieldRenderer method doRender.
/**
* Paints the given WNumberField.
*
* @param component the WNumberField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WNumberField field = (WNumberField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = field.isReadOnly();
BigDecimal value = field.getValue();
String userText = field.getText();
xml.appendTagOpen("ui:numberfield");
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 {
WComponent submitControl = field.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
BigDecimal min = field.getMinValue();
BigDecimal max = field.getMaxValue();
BigDecimal step = field.getStep();
int decimals = field.getDecimalPlaces();
xml.appendOptionalAttribute("disabled", field.isDisabled(), "true");
xml.appendOptionalAttribute("required", field.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", field.getToolTip());
xml.appendOptionalAttribute("accessibleText", field.getAccessibleText());
xml.appendOptionalAttribute("min", min != null, String.valueOf(min));
xml.appendOptionalAttribute("max", max != null, String.valueOf(max));
xml.appendOptionalAttribute("step", step != null, String.valueOf(step));
xml.appendOptionalAttribute("decimals", decimals > 0, decimals);
xml.appendOptionalAttribute("buttonId", submitControlId);
}
xml.appendClose();
xml.appendEscaped(value == null ? userText : value.toString());
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
}
xml.appendEndTag("ui:numberfield");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WPanelRenderer method doRender.
/**
* Paints the given container.
*
* @param component the container to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WPanel panel = (WPanel) component;
XmlStringBuilder xml = renderContext.getWriter();
WButton submitButton = panel.getDefaultSubmitButton();
String submitId = submitButton == null ? null : submitButton.getId();
String titleText = panel.getTitleText();
boolean renderChildren = isRenderContent(panel);
xml.appendTagOpen("ui:panel");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
if (PanelMode.LAZY.equals(panel.getMode())) {
xml.appendOptionalAttribute("hidden", !renderChildren, "true");
} else {
xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
}
xml.appendOptionalAttribute("buttonId", submitId);
xml.appendOptionalAttribute("title", titleText);
xml.appendOptionalAttribute("accessKey", Util.upperCase(panel.getAccessKeyAsString()));
xml.appendOptionalAttribute("type", getPanelType(panel));
xml.appendOptionalAttribute("mode", getPanelMode(panel));
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(panel, renderContext);
if (renderChildren) {
renderChildren(panel, renderContext);
} else {
// Content will be loaded via AJAX
xml.append("<ui:content/>");
}
xml.appendEndTag("ui:panel");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WPartialDateFieldRenderer method doRender.
/**
* Paints the given WPartialDateField.
*
* @param component the WPartialDateField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WPartialDateField dateField = (WPartialDateField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = dateField.isReadOnly();
String date = formatDate(dateField);
xml.appendTagOpen("ui:datefield");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", dateField.isHidden(), "true");
xml.appendOptionalAttribute("date", date);
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendAttribute("allowPartial", "true");
xml.appendOptionalAttribute("disabled", dateField.isDisabled(), "true");
xml.appendOptionalAttribute("required", dateField.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", dateField.getToolTip());
xml.appendOptionalAttribute("accessibleText", dateField.getAccessibleText());
WComponent submitControl = dateField.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
xml.appendOptionalAttribute("buttonId", submitControlId);
}
xml.appendClose();
if (date == null) {
xml.appendEscaped(dateField.getText());
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(dateField, renderContext);
}
xml.appendEndTag("ui:datefield");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WPasswordFieldRenderer method doRender.
/**
* Paints the given WPasswordField.
*
* @param component the WPasswordField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WPasswordField field = (WPasswordField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = field.isReadOnly();
xml.appendTagOpen(TAG_NAME);
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");
xml.appendEnd();
return;
}
int cols = field.getColumns();
int minLength = field.getMinLength();
int maxLength = field.getMaxLength();
WComponent submitControl = field.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
xml.appendOptionalAttribute("disabled", field.isDisabled(), "true");
xml.appendOptionalAttribute("required", field.isMandatory(), "true");
xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
xml.appendOptionalAttribute("toolTip", field.getToolTip());
xml.appendOptionalAttribute("accessibleText", field.getAccessibleText());
xml.appendOptionalAttribute("size", cols > 0, cols);
xml.appendOptionalAttribute("buttonId", submitControlId);
xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(field));
List<Diagnostic> diags = field.getDiagnostics(Diagnostic.ERROR);
if (diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
xml.appendEndTag(TAG_NAME);
}
Aggregations