Search in sources :

Example 91 with UIContext

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");
}
Also used : WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) Map(java.util.Map)

Example 92 with UIContext

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();
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) TableTreeNode(com.github.bordertech.wcomponents.TableTreeNode) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) UIContext(com.github.bordertech.wcomponents.UIContext) TreeTableDataModel(com.github.bordertech.wcomponents.TreeTableDataModel) TableDataModel(com.github.bordertech.wcomponents.TableDataModel) WRepeater(com.github.bordertech.wcomponents.WRepeater)

Example 93 with UIContext

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

Example 94 with UIContext

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;
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) HttpSession(javax.servlet.http.HttpSession)

Example 95 with UIContext

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

Aggregations

UIContext (com.github.bordertech.wcomponents.UIContext)114 Test (org.junit.Test)47 WComponent (com.github.bordertech.wcomponents.WComponent)18 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)15 SystemException (com.github.bordertech.wcomponents.util.SystemException)14 WApplication (com.github.bordertech.wcomponents.WApplication)13 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)11 WText (com.github.bordertech.wcomponents.WText)11 PrintWriter (java.io.PrintWriter)11 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)10 SeleniumWComponentsWebDriver (com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver)9 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)7 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)7 WDropdown (com.github.bordertech.wcomponents.WDropdown)7 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)7 StringWriter (java.io.StringWriter)7 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)6 Environment (com.github.bordertech.wcomponents.Environment)6 MockWEnvironment (com.github.bordertech.wcomponents.MockWEnvironment)6 WButton (com.github.bordertech.wcomponents.WButton)6