Search in sources :

Example 51 with XmlStringBuilder

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");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) SystemException(com.github.bordertech.wcomponents.util.SystemException) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 52 with XmlStringBuilder

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");
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 53 with XmlStringBuilder

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");
    }
}
Also used : Response(com.github.bordertech.wcomponents.Response) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 54 with XmlStringBuilder

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);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Example 55 with XmlStringBuilder

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");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Duplet(com.github.bordertech.wcomponents.util.Duplet) BorderLayout(com.github.bordertech.wcomponents.layout.BorderLayout) Size(com.github.bordertech.wcomponents.Size) WPanel(com.github.bordertech.wcomponents.WPanel) ArrayList(java.util.ArrayList) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) BorderLayoutConstraint(com.github.bordertech.wcomponents.layout.BorderLayout.BorderLayoutConstraint)

Aggregations

XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)102 WComponent (com.github.bordertech.wcomponents.WComponent)30 SystemException (com.github.bordertech.wcomponents.util.SystemException)17 Size (com.github.bordertech.wcomponents.Size)8 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)7 OptionGroup (com.github.bordertech.wcomponents.OptionGroup)6 UIContext (com.github.bordertech.wcomponents.UIContext)5 WPanel (com.github.bordertech.wcomponents.WPanel)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 WButton (com.github.bordertech.wcomponents.WButton)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)4 WTable (com.github.bordertech.wcomponents.WTable)4 WTableColumn (com.github.bordertech.wcomponents.WTableColumn)4 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 TableDataModel (com.github.bordertech.wcomponents.TableDataModel)3 TreeTableDataModel (com.github.bordertech.wcomponents.TreeTableDataModel)3 WDataTable (com.github.bordertech.wcomponents.WDataTable)3 WRepeater (com.github.bordertech.wcomponents.WRepeater)3 TableModel (com.github.bordertech.wcomponents.WTable.TableModel)3 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)2