Paints the component.

@param renderContext the renderContext to send the output to.
195629
@Override
	public void paint(final RenderContext renderContext) {
		boolean enabled = ConfigurationProperties.getDeveloperDumpUIContext();

		super.paint(renderContext);

		if (enabled) {
			UIContext uic = UIContextHolder.getCurrent();

			// We want to dump the shared WComponent tree (UIC) first, so that all the
			// references from the UI context are shown as such
			Object[] treeAndSession
					= new Object[]{
						uic.getUI(),
						uic
					};

			try {
				ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);

				// We only want to dump the tree once
				boolean treeDumped = "true".equalsIgnoreCase((String) uic.getFwkAttribute(
						UICONTEXT_TREE_DUMPED_KEY));

				if (!treeDumped) {
					uic.setFwkAttribute(UICONTEXT_TREE_DUMPED_KEY, "true");

					// The UI will be the 1st child
					LOG.info("UI dump follows:");
					LOG.info(((ObjectGraphNode) root.getChildAt(0)).toXml());
				}

				// The UI context will be the 2nd child
				LOG.info("UI Context dump follows:");
				LOG.info(((ObjectGraphNode) root.getChildAt(1)).toXml());
			} catch (Exception e) {
				LOG.error("Failed to dump context", e);
			}
		}
	}
693978
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WMenuItemGroup group = (WMenuItemGroup) component;
		XmlStringBuilder xml = renderContext.getWriter();

		xml.appendTagOpen("ui:menugroup");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendClose();

		paintChildren(group, renderContext);

		xml.appendEndTag("ui:menugroup");
	}
962194
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WHiddenComment hiddenComponent = (WHiddenComment) component;
		XmlStringBuilder xml = renderContext.getWriter();

		String hiddenText = hiddenComponent.getText();

		if (!Util.empty(hiddenText)) {
			xml.appendTag("ui:comment");
			xml.appendEscaped(hiddenText);
			xml.appendEndTag("ui:comment");
		}
	}
50336
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WSingleSelect listBox = (WSingleSelect) component;
		XmlStringBuilder xml = renderContext.getWriter();
		String dataKey = listBox.getListCacheKey();
		boolean readOnly = listBox.isReadOnly();
		int rows = listBox.getRows();

		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, 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);
			String autocomplete = listBox.getAutocomplete();
			xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete);
		}
		xml.appendAttribute("single", "true");

		xml.appendClose();

		// Options
		List<?> options = listBox.getOptions();
		boolean renderSelectionsOnly = readOnly || dataKey != null;

		if (options != null) {
			int optionIndex = 0;
			Object selectedOption = 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, selectedOption, renderSelectionsOnly);
					}

					xml.appendEndTag("ui:optgroup");
				} else {
					renderOption(listBox, option, optionIndex++, xml, selectedOption, renderSelectionsOnly);
				}
			}
		}

		if (!readOnly) {
			DiagnosticRenderUtil.renderDiagnostics(listBox, renderContext);
		}
		xml.appendEndTag("ui:listbox");
	}
38657
@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");
	}
644282
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WTimeoutWarning warning = (WTimeoutWarning) component;

		XmlStringBuilder xml = renderContext.getWriter();
		final int timoutPeriod = warning.getTimeoutPeriod();
		if (timoutPeriod > 0) {
			xml.appendTagOpen("ui:session");
			xml.appendAttribute("timeout", String.valueOf(timoutPeriod));
			int warningPeriod = warning.getWarningPeriod();
			xml.appendOptionalAttribute("warn", warningPeriod > 0, warningPeriod);
			xml.appendEnd();
		}

	}
1279775
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WTemplate template = (WTemplate) component;

		// Setup the context
		Map<String, Object> context = new HashMap<>();
		// Make the component available under the "wc" key.
		context.put("wc", template);
		// Load the parameters
		context.putAll(template.getParameters());

		// Get template renderer for the engine
		String engine = template.getEngineName();
		if (Util.empty(engine)) {
			engine = ConfigurationProperties.getDefaultRenderingEngine();
		}
		TemplateRenderer templateRenderer = TemplateRendererFactory.newInstance(engine);

		// Render
		if (!Util.empty(template.getTemplateName())) {
			// Render the template
			templateRenderer.renderTemplate(template.getTemplateName(), context, template.getTaggedComponents(), renderContext.getWriter(),
					template.getEngineOptions());
		} else if (!Util.empty(template.getInlineTemplate())) {
			// Render inline
			templateRenderer.renderInline(template.getInlineTemplate(), context, template.getTaggedComponents(), renderContext.getWriter(),
					template.getEngineOptions());
		}
	}
1367313
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WPanel panel = (WPanel) component;
		XmlStringBuilder xml = renderContext.getWriter();
		BorderLayout layout = (BorderLayout) panel.getLayout();
		Size hgap = layout.getHorizontalGap();
		String hgapString = hgap == null ? null : hgap.toString();
		Size vgap = layout.getVerticalGap();
		String vgapString = vgap == null ? null : vgap.toString();

		xml.appendTagOpen("ui:borderlayout");

		xml.appendOptionalAttribute("hgap", hgapString);
		xml.appendOptionalAttribute("vgap", vgapString);

		xml.appendClose();

		// Fetch the children and their constraints.
		final int childCount = panel.getChildCount();
		List<Duplet<WComponent, BorderLayoutConstraint>> children = new ArrayList<>(childCount);

		for (int i = 0; i < childCount; i++) {
			WComponent child = panel.getChildAt(i);
			children.add(new Duplet<>(child, getConstraints(panel, child)));
		}

		// Now paint them
		paintChildrenWithConstraint(children, renderContext, BorderLayout.NORTH);
		paintChildrenWithConstraint(children, renderContext, BorderLayout.EAST);
		paintChildrenWithConstraint(children, renderContext, BorderLayout.SOUTH);
		paintChildrenWithConstraint(children, renderContext, BorderLayout.WEST);
		paintChildrenWithConstraint(children, renderContext, BorderLayout.CENTER);

		xml.appendEndTag("ui:borderlayout");
	}
921788
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WDataTableRowRenderer renderer = (WDataTableRowRenderer) component;
		XmlStringBuilder xml = renderContext.getWriter();
		WDataTable table = renderer.getTable();
		TableDataModel dataModel = table.getDataModel();
		UIContext uic = UIContextHolder.getCurrent();

		final int numCols = table.getColumnCount();
		int[] columnOrder = table.getColumnOrder();
		int rowIndex = getRowIndex(table, (SubUIContext) uic);
		boolean unselectable = table.getSelectMode() != SelectMode.NONE
				&& !dataModel.isSelectable(rowIndex);

		xml.appendTagOpen("ui:tr");
		xml.appendAttribute("rowIndex", rowIndex);
		xml.appendOptionalAttribute("unselectable", unselectable, "true");
		xml.appendOptionalAttribute("selected", table.getSelectedRows().contains(rowIndex), "true");
		xml.appendOptionalAttribute("filterValues", getFilterValues(dataModel, rowIndex));

		if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
			TableTreeNode node = ((TreeTableDataModel) dataModel).getNodeAtLine(rowIndex);
			boolean expandable = !node.isLeaf() && !node.isExpanded();
			xml.appendOptionalAttribute("expandable", expandable, "true");
		}

		xml.appendClose();

		if (table.isShowRowHeaders()) {
			xml.appendTag("ui:th");
			renderer.getRowHeader().paint(renderContext);
			xml.appendEndTag("ui:th");
		}

		for (int i = 0; i < numCols; i++) {
			int colIndex = columnOrder == null ? i : columnOrder[i];
			WTableColumn col = table.getColumn(colIndex);

			if (col.isVisible()) {
				xml.appendTag("ui:td");
				renderer.getRenderer(colIndex).paint(renderContext);
				xml.appendEndTag("ui:td");
			}
		}

		if (table.getExpandMode() != WDataTable.ExpandMode.NONE && dataModel instanceof TreeTableDataModel) {
			TreeTableDataModel treeModel = (TreeTableDataModel) dataModel;
			TableTreeNode node = treeModel.getNodeAtLine(rowIndex);

			if (!node.isLeaf()) {
				xml.appendTagOpen("ui:subtr");
				xml.appendOptionalAttribute("open", node.isExpanded(), "true");
				xml.appendClose();

				if (node.isExpanded() || table.getExpandMode() == ExpandMode.CLIENT) {
					WRepeater repeater = table.getRepeater();

					// If there a renderer specified by any child, we only paint content that has a specified renderer
					boolean rendererPresent = false;

					for (Iterator<TreeNode> i = node.children(); !rendererPresent && i.hasNext();) {
						TableTreeNode child = (TableTreeNode) i.next();

						if (child.getRendererClass() != null) {
							rendererPresent = true;
						}
					}

					// Paint immediate children only.
					if (rendererPresent) {
						xml.appendTagOpen("ui:content");
						xml.appendOptionalAttribute("spanAllCols", node.isRendererSpansAllCols(),
								"true");
						xml.appendClose();

						for (Iterator<TreeNode> i = node.children(); i.hasNext();) {
							TableTreeNode child = (TableTreeNode) i.next();
							Integer rowId = child.getRowIndex() - 1;
							UIContext nodeContext = repeater.getRowContext(rowId);

							WComponent expandedRenderer = renderer.getExpandedTreeNodeRenderer(
									child.getRendererClass());

							if (expandedRenderer != null) {
								UIContextHolder.pushContext(nodeContext);

								try {
									expandedRenderer.paint(renderContext);
								} finally {
									UIContextHolder.popContext();
								}
							}
						}

						xml.appendEndTag("ui:content");
					} else {
						for (Iterator<TreeNode> i = node.children(); i.hasNext();) {
							TableTreeNode child = (TableTreeNode) i.next();
							Integer rowId = child.getRowIndex() - 1;
							UIContext nodeContext = repeater.getRowContext(rowId);

							UIContextHolder.pushContext(nodeContext);

							try {
								render(component, renderContext);
							} finally {
								UIContextHolder.popContext();
							}
						}
					}
				}

				xml.appendEndTag("ui:subtr");
			}
		}

		xml.appendEndTag("ui:tr");
	}
278549
protected void paintRows(final WRepeater repeater, final WebXmlRenderContext renderContext) {
		List<?> beanList = repeater.getBeanList();
		WComponent row = repeater.getRepeatedComponent();

		for (int i = 0; i < beanList.size(); i++) {
			Object rowData = beanList.get(i);

			// Each row has its own context. This is why we can reuse the same
			// WComponent instance for each row.
			UIContext rowContext = repeater.getRowContext(rowData, i);
			UIContextHolder.pushContext(rowContext);

			try {
				row.paint(renderContext);
			} finally {
				UIContextHolder.popContext();
			}
		}
	}
403589
@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");
	}
358594
public static void renderDiagnostics(final Diagnosable component, final WebXmlRenderContext renderContext) {
		List<Diagnostic> diags = component.getDiagnostics(Diagnostic.ERROR);
		if (diags != null) {
			renderHelper(renderContext, component, diags, Diagnostic.ERROR);
		}
		diags = component.getDiagnostics(Diagnostic.WARNING);
		if (diags != null) {
			renderHelper(renderContext, component, diags, Diagnostic.WARNING);
		}
		diags = component.getDiagnostics(Diagnostic.INFO);
		if (diags != null) {
			renderHelper(renderContext, component, diags, Diagnostic.INFO);
		}
		diags = component.getDiagnostics(Diagnostic.SUCCESS);
		if (diags != null) {
			renderHelper(renderContext, component, diags, Diagnostic.SUCCESS);
		}
	}
527115
@Override
	protected void paintComponent(final RenderContext renderContext) {
		if (renderContext instanceof WebXmlRenderContext) {
			PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
			writer.println(getMessage());

			if (developerFriendly) {
				writer.println("<pre style=\"background: lightgrey\">");
				writer.println("Additional details for the developer:");
				writer.println();
				error.printStackTrace(writer);
				writer.println("</pre>");
			}
		}
	}
951825
@Override
	public void paint(final RenderContext renderContext) {
		// Set headers
		getResponse().setHeader("Cache-Control", type.getSettings());

		// Add extra no cache headers
		if (!type.isCache()) {
			getResponse().setHeader("Pragma", "no-cache");
			getResponse().setHeader("Expires", "-1");
		}

		super.paint(renderContext);
	}
11767
@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);
			String placeholder = textArea.getPlaceholder();
			xml.appendOptionalAttribute("placeholder", !Util.empty(placeholder), placeholder);

			String autocomplete = textArea.getAutocomplete();
			xml.appendOptionalAttribute("autocomplete", !Util.empty(autocomplete), autocomplete);
		}
		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");
	}
203783
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WHeading heading = (WHeading) component;
		XmlStringBuilder xml = renderContext.getWriter();

		xml.appendTagOpen("ui:heading");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendAttribute("level", heading.getHeadingLevel().getLevel());
		xml.appendOptionalAttribute("accessibleText", heading.getAccessibleText());
		xml.appendClose();

		// Render margin
		MarginRendererUtil.renderMargin(heading, renderContext);

		if (heading.getDecoratedLabel() == null) {
			// Constructed with a String
			xml.append(heading.getText(), heading.isEncodeText());
		} else {
			heading.getDecoratedLabel().paint(renderContext);
		}

		xml.appendEndTag("ui:heading");
	}
244548
@Override
	public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
		WSuggestions suggestions = (WSuggestions) component;
		XmlStringBuilder xml = renderContext.getWriter();

		// Cache key for a lookup table
		String dataKey = suggestions.getListCacheKey();
		// Use AJAX if not using a cached list and have a refresh action
		boolean useAjax = dataKey == null && suggestions.getRefreshAction() != null;

		// Start tag
		xml.appendTagOpen("ui:suggestions");
		xml.appendAttribute("id", component.getId());
		xml.appendOptionalAttribute("class", component.getHtmlClass());
		xml.appendOptionalAttribute("track", component.isTracking(), "true");
		xml.appendOptionalAttribute("min", suggestions.getMinRefresh() > 0, suggestions.
				getMinRefresh());
		xml.appendOptionalAttribute("ajax", useAjax, "true");
		xml.appendOptionalAttribute("data", dataKey);
		WSuggestions.Autocomplete autocomplete = suggestions.getAutocomplete();
		if (autocomplete == WSuggestions.Autocomplete.LIST) {
			xml.appendOptionalAttribute("autocomplete", "list");
		}
		xml.appendClose();

		// Check if this is the current AJAX trigger
		boolean isTrigger = useAjax && AjaxHelper.isCurrentAjaxTrigger(suggestions);

		// Render suggestions
		if (isTrigger || (dataKey == null && !useAjax)) {
			for (String suggestion : suggestions.getSuggestions()) {
				xml.appendTagOpen("ui:suggestion");
				xml.appendAttribute("value", suggestion);
				xml.appendEnd();
			}
		}

		// End tag
		xml.appendEndTag("ui:suggestions");
	}