use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor method handleRenderRedirect.
/**
* Redirect the user via the AJAX response.
*
* @param writer the print writer for the response
*/
private void handleRenderRedirect(final PrintWriter writer) {
UIContext uic = UIContextHolder.getCurrent();
// Redirect user to error page
LOG.warn("User will be redirected to " + redirectUrl);
// Setup response with redirect
getResponse().setContentType(WebUtilities.CONTENT_TYPE_XML);
writer.write(XMLUtil.getXMLDeclarationWithThemeXslt(uic));
writer.print("<ui:ajaxresponse ");
writer.print(XMLUtil.UI_NAMESPACE);
writer.print(">");
writer.print("<ui:ajaxtarget id=\"" + triggerId + "\" action=\"replace\">");
// Redirect URL
writer.print("<ui:redirect url=\"" + redirectUrl + "\" />");
writer.print("</ui:ajaxtarget>");
writer.print("</ui:ajaxresponse>");
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WrongStepServerInterceptor method preparePaint.
/**
* {@inheritDoc}
*/
@Override
public void preparePaint(final Request request) {
// Increment the step counter
UIContext uic = UIContextHolder.getCurrent();
StepCountUtil.incrementSessionStep(uic);
super.preparePaint(request);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class VelocityRenderer method fillContext.
/**
* Fills the given velocity context with data from the component which is being rendered. A map of components is
* also built up, in order to support deferred rendering.
*
* @param component the current component being rendered.
* @param context the velocity context to modify.
* @param componentsByKey a map to store components for deferred rendering.
*/
private void fillContext(final WComponent component, final VelocityContext context, final Map<String, WComponent> componentsByKey) {
// Also make the component available under the "this" key.
context.put("this", component);
// Make the UIContext available under the "uicontext" key.
UIContext uic = UIContextHolder.getCurrent();
context.put("uicontext", uic);
context.put("uic", uic);
if (component instanceof VelocityProperties) {
Map<?, ?> map = ((VelocityProperties) component).getVelocityMap();
for (Map.Entry<?, ?> entry : map.entrySet()) {
String key = (String) entry.getKey();
Object value = entry.getValue();
context.put(key, value);
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Handling children");
}
// As well as going into their own named slots, visible children are also
// placed into a list called children
ArrayList<String> children = new ArrayList<>();
if (component instanceof Container) {
Container container = (Container) component;
for (int i = 0; i < container.getChildCount(); i++) {
WComponent child = container.getChildAt(i);
String tag = child.getTag();
if (tag != null || child.isVisible()) {
// The key needs to be something which would never be output by a Velocity template.
String key = "<VelocityLayout" + child.getId() + "/>";
componentsByKey.put(key, child);
if (tag != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Adding child " + tag + " to context");
}
addToContext(context, tag, key);
}
if (child.isVisible()) {
children.add(key);
}
}
}
context.put("children", children);
}
// Put the context in the context
context.put("context", context);
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WDataTableRowRendererRenderer method doRender.
/**
* Paints the given WDataTableRowRenderer.
*
* @param component the WDataTableRowRenderer to paint.
* @param renderContext the RenderContext to paint to.
*/
@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");
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class SubordinateControlHelper method applyRegisteredControls.
/**
* Apply the registered Subordinate Controls.
*
* @param request the request being processed.
* @param useRequestValues the flag to indicate the controls should use values from the request.
*/
public static void applyRegisteredControls(final Request request, final boolean useRequestValues) {
Set<String> controls = getRegisteredSubordinateControls();
if (controls == null) {
return;
}
// Process Controls
for (String controlId : controls) {
// Find the Component for this ID
ComponentWithContext controlWithContext = WebUtilities.getComponentById(controlId, true);
if (controlWithContext == null) {
LOG.warn("Subordinate control for id " + controlId + " is no longer in the tree.");
continue;
}
if (!(controlWithContext.getComponent() instanceof WSubordinateControl)) {
LOG.warn("Component for id " + controlId + " is not a subordinate control.");
continue;
}
WSubordinateControl control = (WSubordinateControl) controlWithContext.getComponent();
UIContext uic = controlWithContext.getContext();
UIContextHolder.pushContext(uic);
try {
if (useRequestValues) {
control.applyTheControls(request);
} else {
control.applyTheControls();
}
} finally {
UIContextHolder.popContext();
}
}
}
Aggregations