use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WApplicationRenderer method doRender.
/**
* Paints the given WApplication.
*
* @param component the WApplication to paint.
* @param renderContext the RenderContext to paint to.
*/
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
WApplication application = (WApplication) component;
XmlStringBuilder xml = renderContext.getWriter();
UIContext uic = UIContextHolder.getCurrent();
String focusId = uic.getFocussedId();
// Check that this is the top level component
if (application.getParent() != null) {
LOG.warn("WApplication component should be the top level component.");
}
xml.appendTagOpen("ui:application");
xml.appendAttribute("id", component.getId());
xml.appendOptionalAttribute("class", component.getHtmlClass());
xml.appendUrlAttribute("applicationUrl", uic.getEnvironment().getPostPath());
xml.appendUrlAttribute("ajaxUrl", uic.getEnvironment().getWServletPath());
xml.appendOptionalAttribute("unsavedChanges", application.hasUnsavedChanges(), "true");
xml.appendOptionalAttribute("title", application.getTitle());
xml.appendOptionalAttribute("defaultFocusId", uic.isFocusRequired() && !Util.empty(focusId), focusId);
xml.appendOptionalUrlAttribute("icon", WApplication.getIcon());
xml.appendClose();
// Tracking enabled globally
if (TrackingUtil.isTrackingEnabled()) {
xml.appendTagOpen("ui:analytic");
xml.appendAttribute("clientId", TrackingUtil.getClientId());
xml.appendOptionalAttribute("cd", TrackingUtil.getCookieDomain());
xml.appendOptionalAttribute("dcd", TrackingUtil.getDataCollectionDomain());
xml.appendOptionalAttribute("name", TrackingUtil.getApplicationName());
xml.appendEnd();
}
// Hidden fields
Map<String, String> hiddenFields = uic.getEnvironment().getHiddenParameters();
if (hiddenFields != null) {
for (Map.Entry<String, String> entry : hiddenFields.entrySet()) {
xml.appendTagOpen("ui:param");
xml.appendAttribute("name", entry.getKey());
xml.appendAttribute("value", entry.getValue());
xml.appendEnd();
}
}
// Custom CSS Resources (if any)
for (WApplication.ApplicationResource resource : application.getCssResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:css");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
// Custom JavaScript Resources (if any)
for (WApplication.ApplicationResource resource : application.getJsResources()) {
String url = resource.getTargetUrl();
if (!Util.empty(url)) {
xml.appendTagOpen("ui:js");
xml.appendUrlAttribute("url", url);
xml.appendEnd();
}
}
paintChildren(application, renderContext);
xml.appendEndTag("ui:application");
}
use of com.github.bordertech.wcomponents.UIContext 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.UIContext in project wcomponents by BorderTech.
the class WRepeaterRenderer method paintRows.
/**
* Paints the rows.
*
* @param repeater the repeater to paint the rows for.
* @param renderContext the RenderContext to paint to.
*/
protected void paintRows(final WRepeater repeater, final WebXmlRenderContext renderContext) {
List<?> beanList = repeater.getBeanList();
WComponent row = repeater.getRepeatedComponent();
for (int i = 0; i < beanList.size(); i++) {
Object rowData = beanList.get(i);
// Each row has its own context. This is why we can reuse the same
// WComponent instance for each row.
UIContext rowContext = repeater.getRowContext(rowData, i);
UIContextHolder.pushContext(rowContext);
try {
row.paint(renderContext);
} finally {
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class HttpServletHelper method getUIContext.
/**
* {@inheritDoc}
*/
@Override
protected UIContext getUIContext() {
HttpSession session = getBackingRequest().getSession(false);
if (session == null) {
return null;
}
UIContext uic = (UIContext) session.getAttribute(getUiContextSessionKey());
return uic;
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class ServletUtil method processRequest.
/**
* This method does the real work in servicing the http request. It integrates wcomponents into a servlet
* environment via a servlet specific helper class.
*
* @param helper the servlet helper
* @param ui the application ui
* @param interceptorChain the chain of interceptors
* @throws ServletException a servlet exception
* @throws IOException an IO Exception
*/
public static void processRequest(final HttpServletHelper helper, final WComponent ui, final InterceptorComponent interceptorChain) throws ServletException, IOException {
try {
// that will service the request/response.
if (interceptorChain == null) {
helper.setWebComponent(ui);
} else {
interceptorChain.attachUI(ui);
helper.setWebComponent(interceptorChain);
}
// Prepare user context
UIContext uic = helper.prepareUserContext();
synchronized (uic) {
// Process the action phase.
helper.processAction();
// Process the render phase.
helper.render();
}
} finally {
// We need to ensure that the AJAX operation is cleared
// The interceptors can not guarantee this
// TODO: Investigate changing to not use a thread-local
AjaxHelper.clearCurrentOperationDetails();
}
}
Aggregations