Search in sources :

Example 61 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class AbstractContainerHelper method createUIContext.

/**
 * Creates and initialises a new UIContext.
 *
 * @return a new UIContext.
 */
protected UIContext createUIContext() {
    // Create UIC
    UIContext uic = new UIContextImpl();
    uic.setUI(getUI());
    return uic;
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl)

Example 62 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class AbstractContainerHelper method prepareUserContext.

/**
 * Prepare the user context for this request.
 * <p>
 * This must be called before processAction and render.
 * </p>
 *
 * @return the user context
 */
public UIContext prepareUserContext() {
    UIContext uic = getUIContext();
    if (requestImpliesNew() || uic == null) {
        LOG.debug("Preparing a new session");
        setNewConversation(Boolean.TRUE);
        uic = createUIContext();
        setUIContext(uic);
    } else {
        setNewConversation(Boolean.FALSE);
        // In Development mode, simulate running in a cluster
        cycleUIContext();
    }
    return uic;
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext)

Example 63 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class AjaxInterceptor method serviceRequest.

/**
 * {@inheritDoc}
 */
@Override
public void serviceRequest(final Request request) {
    String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
    AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation();
    if (ajaxOperation == null) {
        throw new IllegalStateException("No AJAX operation available for trigger " + triggerId + ".");
    }
    ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext();
    if (triggerWithContext == null) {
        throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
    }
    UIContext uic = UIContextHolder.getCurrent();
    // Reset the focus for this new request.
    uic.setFocussed(null, null);
    // We've hit the action phase, so we do want focus on this app.
    uic.setFocusRequired(true);
    // Process trigger only
    if (isProcessTriggerOnly(triggerWithContext, ajaxOperation)) {
        // Get user context
        UIContext tuic = triggerWithContext.getContext();
        UIContextHolder.pushContext(tuic);
        try {
            WComponent trigger = triggerWithContext.getComponent();
            trigger.serviceRequest(request);
            // Manually invoke laters as the InvokeLaters in the service request is not run due to the trigger
            // having a "parent"
            tuic.doInvokeLaters();
        } finally {
            UIContextHolder.popContext();
        }
    } else if ("GET".equals(request.getMethod())) {
        // GET only supports the above scenarios
        throw new IllegalStateException("GET is not supported for the AJAX trigger " + triggerId + ".");
    } else {
        // service the request
        super.serviceRequest(request);
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) UIContext(com.github.bordertech.wcomponents.UIContext) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 64 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class DevToolkit method getTree.

/**
 * Retrieves a tree representation of the WComponent UI being served by the LDE, in a format suitable for rendering
 * to the UI.
 *
 * @return a tree representation of the WComponent UI.
 */
public TreeNode getTree() {
    UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
    String[] debugTree = uic.getUI().toString().split("\n");
    TreeNode root = new UITreeNode(debugTree[0]);
    TreeNode parent = root;
    TreeNode last = root;
    for (int i = 1; i < debugTree.length; i++) {
        String line = debugTree[i].trim();
        if (line.charAt(0) == '[') {
            parent = last;
            TreeNode child = new UITreeNode(debugTree[++i]);
            parent.add(child);
            last = child;
        } else if (line.charAt(0) == ']') {
            parent = parent.getParent();
        } else {
            TreeNode child = new UITreeNode(debugTree[i]);
            parent.add(child);
            last = child;
        }
    }
    return root;
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) TreeNode(com.github.bordertech.wcomponents.util.TreeNode) AbstractTreeNode(com.github.bordertech.wcomponents.util.AbstractTreeNode)

Example 65 with UIContext

use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.

the class ByWComponentPath method findElements.

/**
 * {@inheritDoc}
 */
@Override
public List<WebElement> findElements(final SearchContext searchContext) {
    List<WebElement> result = new ArrayList<>();
    ComponentWithContext[] components = null;
    UIContextHolder.pushContext(getContext());
    try {
        components = TreeUtil.findWComponents(getComponent(), path, visibleOnly);
    } finally {
        UIContextHolder.popContext();
    }
    if (components.length != 0) {
        componentClass = components[0].getComponent().getClass();
    }
    for (ComponentWithContext comp : components) {
        WComponent cmp = comp.getComponent();
        UIContext cmpUic = comp.getContext();
        UIContextHolder.pushContext(cmpUic);
        try {
            List<WebElement> resultForComp = findElement(searchContext, cmpUic, cmp, getValue());
            result.addAll(resultForComp);
        } finally {
            UIContextHolder.popContext();
        }
    }
    return result;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) UIContext(com.github.bordertech.wcomponents.UIContext) ArrayList(java.util.ArrayList) WebElement(org.openqa.selenium.WebElement) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

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