use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class VelocityRenderer method paintXml.
/**
* Paints the component in XML using the Velocity Template.
*
* @param component the component to paint.
* @param writer the writer to send the HTML output to.
*/
public void paintXml(final WComponent component, final Writer writer) {
if (LOG.isDebugEnabled()) {
LOG.debug("paintXml called for component class " + component.getClass());
}
String templateText = null;
if (component instanceof AbstractWComponent) {
AbstractWComponent abstractComp = ((AbstractWComponent) component);
templateText = abstractComp.getTemplateMarkUp();
}
try {
Map<String, WComponent> componentsByKey = new HashMap<>();
VelocityContext context = new VelocityContext();
fillContext(component, context, componentsByKey);
VelocityWriter velocityWriter = new VelocityWriter(writer, componentsByKey, UIContextHolder.getCurrent());
if (templateText != null) {
VelocityEngine engine = VelocityEngineFactory.getVelocityEngine();
engine.evaluate(context, velocityWriter, component.getClass().getSimpleName(), templateText);
} else {
Template template = getTemplate(component);
if (template == null) {
LOG.warn("VelocityRenderer invoked for a component with no template: " + component.getClass().getName());
} else {
template.merge(context, velocityWriter);
}
}
velocityWriter.close();
if (component instanceof VelocityProperties) {
((VelocityProperties) component).mapUsed();
}
} catch (ResourceNotFoundException rnfe) {
LOG.error("Could not find template '" + url + "' for component " + component.getClass().getName(), rnfe);
} catch (ParseErrorException pee) {
// syntax error : problem parsing the template
LOG.error("Parse problems", pee);
} catch (MethodInvocationException mie) {
// something invoked in the template
// threw an exception
Throwable wrapped = mie.getWrappedThrowable();
LOG.error("Problems with velocity", mie);
if (wrapped != null) {
LOG.error("Wrapped exception...", wrapped);
}
} catch (Exception e) {
LOG.error("Problems with velocity", e);
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WAjaxControlRenderer method doRender.
/**
* Paints the given AjaxControl.
*
* @param component the AjaxControl to paint
* @param renderContext the RenderContext to paint to
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WAjaxControl ajaxControl = (WAjaxControl) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent trigger = ajaxControl.getTrigger() == null ? ajaxControl : ajaxControl.getTrigger();
int delay = ajaxControl.getDelay();
if (ajaxControl.getTargets() == null || ajaxControl.getTargets().isEmpty()) {
return;
}
// Start tag
xml.appendTagOpen("ui:ajaxtrigger");
xml.appendAttribute("triggerId", trigger.getId());
xml.appendOptionalAttribute("loadOnce", ajaxControl.isLoadOnce(), "true");
xml.appendOptionalAttribute("delay", delay > 0, delay);
xml.appendClose();
// Targets
for (AjaxTarget target : ajaxControl.getTargets()) {
xml.appendTagOpen("ui:ajaxtargetid");
xml.appendAttribute("targetId", target.getId());
xml.appendEnd();
}
// End tag
xml.appendEndTag("ui:ajaxtrigger");
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WButtonRenderer method doRender.
/**
* Paints the given WButton.
*
* @param component the WButton to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
XmlStringBuilder xml = renderContext.getWriter();
WButton button = (WButton) component;
String text = button.getText();
String imageUrl = button.getImageUrl();
String accessibleText = button.getAccessibleText();
String toolTip = button.getToolTip();
if (Util.empty(text) && imageUrl == null && Util.empty(accessibleText) && Util.empty(toolTip)) {
throw new SystemException("WButton text or imageUrl must be specified");
}
xml.appendTagOpen(getTagName(button));
String buttonId = button.getId();
ImagePosition pos = button.getImagePosition();
if (Util.empty(text) && Util.empty(toolTip) && Util.empty(accessibleText)) {
// If the button has an imageUrl but no text equivalent get the text equivalent off of the image
WImage imgHolder = button.getImageHolder();
if (null != imgHolder) {
toolTip = imgHolder.getAlternativeText();
}
}
xml.appendAttribute("id", buttonId);
xml.appendAttribute("name", buttonId);
xml.appendAttribute("value", "x");
xml.appendAttribute("type", getButtonType(button));
xml.appendAttribute("class", geHtmlClassName(button));
xml.appendOptionalAttribute("disabled", button.isDisabled(), "disabled");
xml.appendOptionalAttribute("hidden", button.isHidden(), "hidden");
xml.appendOptionalAttribute("title", toolTip);
xml.appendOptionalAttribute("aria-label", accessibleText);
xml.appendOptionalAttribute("aria-haspopup", button.isPopupTrigger(), "true");
xml.appendOptionalAttribute("accesskey", Util.upperCase(button.getAccessKeyAsString()));
xml.appendOptionalAttribute("data-wc-btnmsg", button.getMessage());
if (button.isCancel()) {
xml.appendAttribute("formnovalidate", "formnovalidate");
} else {
Action action = button.getAction();
if (action instanceof ValidatingAction) {
WComponent validationTarget = ((ValidatingAction) action).getComponentToValidate();
xml.appendAttribute("data-wc-validate", validationTarget.getId());
}
}
xml.appendClose();
if (imageUrl != null) {
xml.appendTagOpen("span");
String imageHolderClass = "wc_nti";
if (pos != null) {
StringBuffer imageHolderClassBuffer = new StringBuffer("wc_btn_img wc_btn_img");
switch(pos) {
case NORTH:
imageHolderClassBuffer.append("n");
break;
case EAST:
imageHolderClassBuffer.append("e");
break;
case SOUTH:
imageHolderClassBuffer.append("s");
break;
case WEST:
imageHolderClassBuffer.append("w");
break;
default:
throw new SystemException("Unknown image position: " + pos);
}
imageHolderClass = imageHolderClassBuffer.toString();
}
xml.appendAttribute("class", imageHolderClass);
xml.appendClose();
if (pos != null && text != null) {
xml.appendTag("span");
xml.appendEscaped(text);
xml.appendEndTag("span");
}
xml.appendTagOpen("img");
xml.appendUrlAttribute("src", imageUrl);
String alternateText = pos == null ? text : "";
xml.appendAttribute("alt", alternateText);
xml.appendEnd();
xml.appendEndTag("span");
} else if (text != null) {
xml.appendEscaped(text);
}
xml.appendEndTag(getTagName(button));
if (button.isAjax()) {
paintAjax(button, xml);
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WDataTableRenderer method doPaintRows.
/**
* Override paintRow so that we only paint the first-level nodes for tree-tables.
*
* @param table the table to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
private void doPaintRows(final WDataTable table, final WebXmlRenderContext renderContext) {
TableDataModel model = table.getDataModel();
WRepeater repeater = table.getRepeater();
List<?> beanList = repeater.getBeanList();
final int rowCount = beanList.size();
WComponent row = repeater.getRepeatedComponent();
for (int i = 0; i < rowCount; i++) {
if (model instanceof TreeTableDataModel) {
Integer nodeIdx = (Integer) beanList.get(i);
TableTreeNode node = ((TreeTableDataModel) model).getNodeAtLine(nodeIdx);
if (node.getLevel() != 1) {
// Handled by the layout, so don't paint the row.
continue;
}
}
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = repeater.getRowContext(beanList.get(i), i);
UIContextHolder.pushContext(rowContext);
try {
row.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WDecoratedLabelRenderer method doRender.
/**
* Paints the given WDecoratedLabel.
*
* @param component the WDecoratedLabel to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WDecoratedLabel label = (WDecoratedLabel) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent head = label.getHead();
WComponent body = label.getBody();
WComponent tail = label.getTail();
xml.appendTagOpen("ui:decoratedlabel");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", label.isHidden(), "true");
xml.appendClose();
if (head != null && head.isVisible()) {
xml.appendTagOpen("ui:labelhead");
xml.appendAttribute("id", label.getId() + "-head");
xml.appendClose();
head.paint(renderContext);
xml.appendEndTag("ui:labelhead");
}
xml.appendTagOpen("ui:labelbody");
xml.appendAttribute("id", label.getId() + "-body");
xml.appendClose();
body.paint(renderContext);
xml.appendEndTag("ui:labelbody");
if (tail != null && tail.isVisible()) {
xml.appendTagOpen("ui:labeltail");
xml.appendAttribute("id", label.getId() + "-tail");
xml.appendClose();
tail.paint(renderContext);
xml.appendEndTag("ui:labeltail");
}
xml.appendEndTag("ui:decoratedlabel");
}
Aggregations