use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WDropdownRenderer method doRender.
/**
* Paints the given WDropdown.
*
* @param component the WDropdown to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDropdown dropdown = (WDropdown) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = dropdown.isReadOnly();
String dataKey = dropdown.getListCacheKey();
// Start tag
xml.appendTagOpen("ui:dropdown");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", dropdown.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
xml.appendOptionalAttribute("data", dataKey != null, dataKey);
xml.appendOptionalAttribute("disabled", dropdown.isDisabled(), "true");
xml.appendOptionalAttribute("required", dropdown.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", dropdown.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", dropdown.getToolTip());
xml.appendOptionalAttribute("accessibleText", dropdown.getAccessibleText());
int optionWidth = dropdown.getOptionWidth();
xml.appendOptionalAttribute("optionWidth", optionWidth > 0, optionWidth);
xml.appendOptionalAttribute("type", getTypeAsString(dropdown.getType()));
}
xml.appendClose();
// Options
List<?> options = dropdown.getOptions();
Object selectedOption = dropdown.getSelected();
// For an editable dropdown (combo box), the selected option may not be in the list.
if (dropdown.getType() == WDropdown.DropdownType.COMBO && selectedOption != null && (options == null || !options.contains(selectedOption))) {
xml.appendTagOpen("ui:option");
xml.appendAttribute("value", selectedOption.toString());
xml.appendAttribute("selected", "true");
xml.appendClose();
xml.appendEscaped(selectedOption.toString());
xml.appendEndTag("ui:option");
}
if (options != null) {
int optionIndex = 0;
boolean renderSelectionsOnly = readOnly || dataKey != null;
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(dropdown, nestedOption, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
xml.appendEndTag("ui:optgroup");
} else {
renderOption(dropdown, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
}
}
}
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(dropdown, renderContext);
}
// End tag
xml.appendEndTag("ui:dropdown");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WEmailFieldRenderer method doRender.
/**
* Paints the given WEmailField.
*
* @param component the WEmailField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WEmailField field = (WEmailField) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = field.isReadOnly();
xml.appendTagOpen("ui:emailfield");
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 = field.getColumns();
int maxLength = field.getMaxLength();
WSuggestions suggestions = field.getSuggestions();
String suggestionsId = suggestions == null ? null : suggestions.getId();
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("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("list", suggestionsId);
xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(field));
}
xml.appendClose();
xml.appendEscaped(field.getText());
if (!readOnly) {
DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
}
xml.appendEndTag("ui:emailfield");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WFieldRenderer method doRender.
/**
* Paints the given WField.
*
* @param component the WField to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WField field = (WField) component;
XmlStringBuilder xml = renderContext.getWriter();
int inputWidth = field.getInputWidth();
xml.appendTagOpen("ui:field");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", field.isHidden(), "true");
xml.appendOptionalAttribute("inputWidth", inputWidth > 0, inputWidth);
xml.appendClose();
// Label
WLabel label = field.getLabel();
if (label != null) {
label.paint(renderContext);
}
// Field
if (field.getField() != null) {
xml.appendTag("ui:input");
field.getField().paint(renderContext);
if (field.getErrorIndicator() != null) {
field.getErrorIndicator().paint(renderContext);
}
if (field.getWarningIndicator() != null) {
field.getWarningIndicator().paint(renderContext);
}
xml.appendEndTag("ui:input");
}
xml.appendEndTag("ui:field");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WFieldSetRenderer method doRender.
/**
* Paints the given WFieldSet.
*
* @param component the WFieldSet to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WFieldSet fieldSet = (WFieldSet) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:fieldset");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", fieldSet.isHidden(), "true");
switch(fieldSet.getFrameType()) {
case NO_BORDER:
xml.appendOptionalAttribute("frame", "noborder");
break;
case NO_TEXT:
xml.appendOptionalAttribute("frame", "notext");
break;
case NONE:
xml.appendOptionalAttribute("frame", "none");
break;
case NORMAL:
default:
break;
}
xml.appendOptionalAttribute("required", fieldSet.isMandatory(), "true");
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(fieldSet, renderContext);
// Label
WDecoratedLabel label = fieldSet.getTitle();
label.paint(renderContext);
// Children
xml.appendTag("ui:content");
int size = fieldSet.getChildCount();
for (int i = 0; i < size; i++) {
WComponent child = fieldSet.getChildAt(i);
// Skip label, as it has already been painted
if (child != label) {
child.paint(renderContext);
}
}
xml.appendEndTag("ui:content");
DiagnosticRenderUtil.renderDiagnostics(fieldSet, renderContext);
xml.appendEndTag("ui:fieldset");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class WFileWidgetRenderer method doRender.
/**
* Paints the given WFileWidget.
*
* @param component the WFileWidget to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WFileWidget fileWidget = (WFileWidget) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = fileWidget.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;
}
xml.appendOptionalAttribute("disabled", fileWidget.isDisabled(), "true");
xml.appendOptionalAttribute("required", fileWidget.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", fileWidget.getToolTip());
xml.appendOptionalAttribute("accessibleText", fileWidget.getAccessibleText());
xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(fileWidget.getFileTypes()));
long maxFileSize = fileWidget.getMaxFileSize();
xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
List<Diagnostic> diags = fileWidget.getDiagnostics(Diagnostic.ERROR);
if (diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
DiagnosticRenderUtil.renderDiagnostics(fileWidget, renderContext);
xml.appendEndTag(TAG_NAME);
}
Aggregations