use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class AjaxInterceptor method paintContainerResponse.
/**
* Paint the ajax container response.
*
* @param renderContext the render context
* @param operation the ajax operation
*/
private void paintContainerResponse(final RenderContext renderContext, final AjaxOperation operation) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
// Get trigger's context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new SystemException("No context available for trigger " + operation.getTriggerId());
}
xml.appendTagOpen("ui:ajaxtarget");
xml.appendAttribute("id", operation.getTargetContainerId());
xml.appendAttribute("action", AjaxOperation.AjaxAction.REPLACE_CONTENT.getDesc());
xml.appendClose();
// Paint targets - Assume targets are in the same context as the trigger
UIContextHolder.pushContext(trigger.getContext());
try {
for (String targetId : operation.getTargets()) {
ComponentWithContext target;
if (targetId.equals(operation.getTriggerId())) {
target = trigger;
} else {
target = WebUtilities.getComponentById(targetId, true);
if (target == null) {
LOG.warn("Could not find ajax target to render [" + targetId + "]");
continue;
}
}
target.getComponent().paint(renderContext);
}
} finally {
UIContextHolder.popContext();
}
xml.appendEndTag("ui:ajaxtarget");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class AjaxPageShellInterceptor method paint.
/**
* Paints the targeted ajax regions. The format of the response is an agreement between the server and the client
* side handling our AJAX response.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
WebXmlRenderContext webRenderContext = (WebXmlRenderContext) renderContext;
XmlStringBuilder xml = webRenderContext.getWriter();
AjaxOperation operation = AjaxHelper.getCurrentOperation();
if (operation == null) {
// the request attribute that we place in the ui contenxt in the action phase can't be null
throw new SystemException("Can't paint AJAX response. Couldn't find the expected reference to the AjaxOperation.");
}
UIContext uic = UIContextHolder.getCurrent();
String focusId = uic.getFocussedId();
xml.append(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
xml.appendTagOpen("ui:ajaxresponse");
xml.append(XMLUtil.STANDARD_NAMESPACES);
xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
xml.appendClose();
getBackingComponent().paint(renderContext);
xml.appendEndTag("ui:ajaxresponse");
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class DataListInterceptor method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(final RenderContext renderContext) {
if (key == null) {
super.paint(renderContext);
return;
}
Response response = getResponse();
Object table = LOOKUP_TABLE.getTableForCacheKey(key);
List<?> data = LOOKUP_TABLE.getTable(table);
response.setContentType(WebUtilities.CONTENT_TYPE_XML);
response.setHeader("Cache-Control", CacheType.DATALIST_CACHE.getSettings());
XmlStringBuilder xml = new XmlStringBuilder(((WebXmlRenderContext) renderContext).getWriter());
xml.write(XMLUtil.XML_DECLARATION);
if (data != null) {
xml.appendTagOpen("ui:datalist");
xml.append(XMLUtil.UI_NAMESPACE);
xml.appendAttribute("id", key);
xml.appendClose();
for (Object item : data) {
// Check for null option (ie null or empty). Match isEmpty() logic.
boolean isNull = item == null ? true : (item.toString().length() == 0);
xml.appendTagOpen("ui:option");
xml.appendAttribute("value", LOOKUP_TABLE.getCode(table, item));
xml.appendOptionalAttribute("isNull", isNull, "true");
xml.appendClose();
xml.append(WebUtilities.encode(LOOKUP_TABLE.getDescription(table, item)));
xml.appendEndTag("ui:option");
}
xml.appendEndTag("ui:datalist");
}
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class BorderLayoutRenderer method paintChildrenWithConstraint.
/**
* Paints all the child components with the given constraint.
*
* @param children the list of potential children to paint.
* @param renderContext the RenderContext to paint to.
* @param constraint the target constraint.
*/
private void paintChildrenWithConstraint(final List<Duplet<WComponent, BorderLayoutConstraint>> children, final WebXmlRenderContext renderContext, final BorderLayoutConstraint constraint) {
String containingTag = null;
XmlStringBuilder xml = renderContext.getWriter();
final int size = children.size();
for (int i = 0; i < size; i++) {
Duplet<WComponent, BorderLayoutConstraint> child = children.get(i);
if (constraint.equals(child.getSecond())) {
if (containingTag == null) {
containingTag = getTag(constraint);
xml.appendTag(containingTag);
}
child.getFirst().paint(renderContext);
}
}
if (containingTag != null) {
xml.appendEndTag(containingTag);
}
}
use of com.github.bordertech.wcomponents.XmlStringBuilder in project wcomponents by BorderTech.
the class BorderLayoutRenderer method doRender.
/**
* Paints the given WPanel's children.
*
* @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();
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");
}
Aggregations