use of com.github.bordertech.wcomponents.WComponent 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.WComponent 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.WComponent in project wcomponents by BorderTech.
the class WLabelRenderer method doRender.
/**
* Paints the given {@link WLabel}.
*
* @param component the WLabel to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WLabel label = (WLabel) component;
XmlStringBuilder xml = renderContext.getWriter();
xml.appendTagOpen("ui:label");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("for", label.getLabelFor());
WComponent what = label.getForComponent();
String whatFor = null;
if (what instanceof MultiInputComponent) {
whatFor = "group";
} else if (what instanceof Labelable) {
whatFor = "input";
}
boolean isReadOnly = ((what instanceof Input) && ((Input) what).isReadOnly()) || (what instanceof WRadioButton && ((WRadioButton) what).isReadOnly());
boolean isMandatory = (what instanceof Input) && ((Input) what).isMandatory();
xml.appendOptionalAttribute("what", whatFor);
xml.appendOptionalAttribute("readonly", isReadOnly, "true");
xml.appendOptionalAttribute("required", isMandatory, "true");
xml.appendOptionalAttribute("hiddencomponent", (what != null && what.isHidden()), "true");
xml.appendOptionalAttribute("hint", label.getHint());
xml.appendOptionalAttribute("accessKey", Util.upperCase(label.getAccessKeyAsString()));
xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
xml.appendOptionalAttribute("toolTip", label.getToolTip());
xml.appendOptionalAttribute("accessibleText", label.getAccessibleText());
xml.appendClose();
xml.append(label.getText(), label.isEncodeText());
paintChildren(label, renderContext);
xml.appendEndTag("ui:label");
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WMultiFileWidgetRenderer method doRender.
/**
* Paints the given WMultiFileWidget.
*
* @param component the WMultiFileWidget to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WMultiFileWidget widget = (WMultiFileWidget) component;
XmlStringBuilder xml = renderContext.getWriter();
// Check if rendering a file upload response
String uploadId = widget.getFileUploadRequestId();
if (uploadId != null) {
handleFileUploadRequest(widget, xml, uploadId);
return;
}
boolean readOnly = widget.isReadOnly();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", widget.isHidden(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
} else {
long maxFileSize = widget.getMaxFileSize();
int maxFiles = widget.getMaxFiles();
WComponent dropzone = widget.getDropzone();
WImageEditor editor = widget.getEditor();
xml.appendOptionalAttribute("disabled", widget.isDisabled(), "true");
xml.appendOptionalAttribute("required", widget.isMandatory(), "true");
xml.appendOptionalAttribute("toolTip", widget.getToolTip());
xml.appendOptionalAttribute("accessibleText", widget.getAccessibleText());
xml.appendOptionalAttribute("acceptedMimeTypes", typesToString(widget.getFileTypes()));
xml.appendOptionalAttribute("maxFileSize", maxFileSize > 0, maxFileSize);
xml.appendOptionalAttribute("maxFiles", maxFiles > 0, maxFiles);
if (dropzone != null) {
xml.appendAttribute("dropzone", dropzone.getId());
}
if (editor != null) {
xml.appendAttribute("editor", editor.getId());
if (editor.getUseCamera()) {
xml.appendAttribute("camera", true);
}
}
}
if (widget.getColumns() != null) {
xml.appendAttribute("cols", widget.getColumns());
}
if (widget.getFileAjaxAction() != null) {
xml.appendAttribute("ajax", "true");
}
List<Diagnostic> diags = readOnly ? null : widget.getDiagnostics(Diagnostic.ERROR);
if (widget.getFiles().isEmpty()) {
if (readOnly || diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
} else {
xml.appendClose();
// Render files
int i = 0;
for (FileWidgetUpload file : widget.getFiles()) {
FileWidgetRendererUtil.renderFileElement(widget, xml, file, i++);
}
}
if (!readOnly && diags != null && !diags.isEmpty()) {
DiagnosticRenderUtil.renderDiagnostics(widget, renderContext);
}
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.WComponent 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");
}
Aggregations