use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class AbstractContainerHelper method handleError.
/**
* Last resort error handling.
*
* @param error the error to handle.
* @throws IOException if there is an error writing the error HTML.
*/
public void handleError(final Throwable error) throws IOException {
LOG.debug("Start handleError...");
// Should the session be removed upon error?
boolean terminate = ConfigurationProperties.getTerminateSessionOnError();
// If we are unfriendly, terminate the session
if (terminate) {
invalidateSession();
}
// Are we in developer friendly error mode?
boolean friendly = ConfigurationProperties.getDeveloperErrorHandling();
FatalErrorPageFactory factory = Factory.newInstance(FatalErrorPageFactory.class);
WComponent errorPage = factory.createErrorPage(friendly, error);
String html = renderErrorPageToHTML(errorPage);
// Setup the response
Response response = getResponse();
response.setContentType(WebUtilities.CONTENT_TYPE_HTML);
// Make sure not cached
getResponse().setHeader("Cache-Control", CacheType.NO_CACHE.getSettings());
getResponse().setHeader("Pragma", "no-cache");
getResponse().setHeader("Expires", "-1");
getPrintWriter().println(html);
LOG.debug("End handleError");
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class AbstractContainerHelper method render.
/**
* Support standard processing of the render phase of a request.
*
* @throws IOException IO Exception
*/
public void render() throws IOException {
if (isDisposed()) {
LOG.debug("Skipping render phase.");
return;
}
try {
// Check user context has been prepared
if (getNewConversation() == null) {
throw new IllegalStateException("User context has not been prepared before the render phase");
}
prepareRender();
UIContext uic = getUIContext();
if (uic == null) {
throw new IllegalStateException("No user context set for the render phase.");
}
UIContextHolder.pushContext(uic);
prepareRequest();
// Handle errors from the action phase now.
if (havePropogatedError()) {
handleError(getPropogatedError());
return;
}
WComponent uiComponent = getUI();
if (uiComponent == null) {
throw new SystemException("No UI Component exists.");
}
Environment environment = uiComponent.getEnvironment();
if (environment == null) {
throw new SystemException("No WEnvironment exists.");
}
getInterceptor().attachResponse(getResponse());
getInterceptor().preparePaint(getRequest());
String contentType = getUI().getHeaders().getContentType();
Response response = getResponse();
response.setContentType(contentType);
addGenericHeaders(uic, getUI());
PrintWriter writer = getPrintWriter();
getInterceptor().paint(new WebXmlRenderContext(writer, uic.getLocale()));
// The following only matters for a Portal context
String title = uiComponent instanceof WApplication ? ((WApplication) uiComponent).getTitle() : null;
if (title != null) {
setTitle(title);
}
} catch (Escape esc) {
LOG.debug("Escape performed during render phase.");
handleEscape(esc);
} catch (Throwable t) {
// We try not to let any exception propagate to container.
String message = "Caught exception during render phase.";
LOG.error(message, t);
handleError(t);
} finally {
UIContextHolder.reset();
dispose();
}
}
use of com.github.bordertech.wcomponents.WComponent 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.WComponent in project wcomponents by BorderTech.
the class WCheckBoxRenderer method doRender.
/**
* Paints the given WCheckBox.
*
* @param component the WCheckBox to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCheckBox checkBox = (WCheckBox) component;
XmlStringBuilder xml = renderContext.getWriter();
boolean readOnly = checkBox.isReadOnly();
xml.appendTagOpen(TAG_NAME);
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendOptionalAttribute("hidden", checkBox.isHidden(), "true");
xml.appendOptionalAttribute("selected", checkBox.isSelected(), "true");
if (readOnly) {
xml.appendAttribute("readOnly", "true");
xml.appendEnd();
return;
}
WComponent submitControl = checkBox.getDefaultSubmitButton();
String submitControlId = submitControl == null ? null : submitControl.getId();
WComponentGroup<WCheckBox> group = checkBox.getGroup();
String groupName = group == null ? null : group.getId();
xml.appendOptionalAttribute("groupName", groupName);
xml.appendOptionalAttribute("disabled", checkBox.isDisabled(), "true");
xml.appendOptionalAttribute("required", checkBox.isMandatory(), "true");
xml.appendOptionalAttribute("submitOnChange", checkBox.isSubmitOnChange(), "true");
xml.appendOptionalAttribute("toolTip", checkBox.getToolTip());
xml.appendOptionalAttribute("accessibleText", checkBox.getAccessibleText());
xml.appendOptionalAttribute("buttonId", submitControlId);
List<Diagnostic> diags = checkBox.getDiagnostics(Diagnostic.ERROR);
if (diags == null || diags.isEmpty()) {
xml.appendEnd();
return;
}
xml.appendClose();
DiagnosticRenderUtil.renderDiagnostics(checkBox, renderContext);
xml.appendEndTag(TAG_NAME);
}
use of com.github.bordertech.wcomponents.WComponent in project wcomponents by BorderTech.
the class WCollapsibleRenderer method doRender.
/**
* Paints the given WCollapsible.
*
* @param component the WCollapsible to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WCollapsible collapsible = (WCollapsible) component;
XmlStringBuilder xml = renderContext.getWriter();
WComponent content = collapsible.getContent();
boolean collapsed = collapsible.isCollapsed();
xml.appendTagOpen("ui:collapsible");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendOptionalAttribute("track", component.isTracking(), "true");
xml.appendAttribute("groupName", collapsible.getGroupName());
xml.appendOptionalAttribute("collapsed", collapsed, "true");
xml.appendOptionalAttribute("hidden", collapsible.isHidden(), "true");
switch(collapsible.getMode()) {
case CLIENT:
xml.appendAttribute("mode", "client");
break;
case LAZY:
xml.appendAttribute("mode", "lazy");
break;
case EAGER:
xml.appendAttribute("mode", "eager");
break;
case DYNAMIC:
xml.appendAttribute("mode", "dynamic");
break;
case SERVER:
xml.appendAttribute("mode", "server");
break;
default:
throw new SystemException("Unknown collapsible mode: " + collapsible.getMode());
}
HeadingLevel level = collapsible.getHeadingLevel();
if (level != null) {
xml.appendAttribute("level", level.getLevel());
}
xml.appendClose();
// Render margin
MarginRendererUtil.renderMargin(collapsible, renderContext);
// Label
collapsible.getDecoratedLabel().paint(renderContext);
// Content
xml.appendTagOpen("ui:content");
xml.appendAttribute("id", component.getId() + "-content");
xml.appendClose();
// Render content if not EAGER Mode or is EAGER and is the current AJAX trigger
if (CollapsibleMode.EAGER != collapsible.getMode() || AjaxHelper.isCurrentAjaxTrigger(collapsible)) {
// Visibility of content set in prepare paint
content.paint(renderContext);
}
xml.appendEndTag("ui:content");
xml.appendEndTag("ui:collapsible");
}
Aggregations