Search in sources :

Example 56 with WComponent

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

the class AutoReFocusExample_Test method testRefocusWDropdown.

@Test
public void testRefocusWDropdown() {
    SeleniumWComponentsWebDriver driver = getDriver();
    String path = "WDropdownSubmitOnChangeExample/WDropdown[0]";
    driver.findWDropdown(byWComponentPath(path)).click();
    UIContext uic = getUserContextForSession();
    UIContextHolder.pushContext(uic);
    try {
        // The dropdowns in the example need something to be selected to trigger the submit
        WComponent comp = TreeUtil.findWComponent(getUi(), path.split("/")).getComponent();
        if (comp instanceof WDropdown) {
            WDropdown dropdown = (WDropdown) comp;
            driver.findElement(byWComponentPath(path, dropdown.getOptions().get(1))).click();
        }
    } finally {
        UIContextHolder.popContext();
    }
    Assert.assertEquals("Incorrect focus", driver.findWDropdown(byWComponentPath(path)).getActiveId(), driver.switchTo(true).activeElement().getAttribute("id"));
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 57 with WComponent

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

the class AutoReFocusRepeaterExample_Test method testAutoReFocusWDropdowns.

@Test
public void testAutoReFocusWDropdowns() {
    SeleniumWComponentsWebDriver driver = getDriver();
    String[] paths = { ROOT_PATH + "[0]/AutoReFocusExample/WDropdown", ROOT_PATH + "[1]/AutoReFocusExample/WDropdown" };
    for (String path : paths) {
        driver.findWDropdown(byWComponentPath(path)).getInputField().click();
        UIContext uic = getUserContextForSession();
        UIContextHolder.pushContext(uic);
        try {
            // The dropdowns in the example need something to be selected to trigger the submit
            WComponent comp = TreeUtil.findWComponent(getUi(), path.split("/"), false).getComponent();
            if (comp instanceof WDropdown) {
                WDropdown dropdown = (WDropdown) comp;
                driver.findElement(byWComponentPath(path, dropdown.getOptions().get(1))).click();
            }
        } finally {
            UIContextHolder.popContext();
        }
        Assert.assertEquals("Incorrect focus", driver.findWDropdown(byWComponentPath(path)).getActiveId(), driver.switchTo(true).activeElement().getAttribute("id"));
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) SeleniumWComponentsWebDriver(com.github.bordertech.wcomponents.test.selenium.driver.SeleniumWComponentsWebDriver) WDropdown(com.github.bordertech.wcomponents.WDropdown) UIContext(com.github.bordertech.wcomponents.UIContext) Test(org.junit.Test)

Example 58 with WComponent

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

the class AjaxInterceptor method isProcessTriggerOnly.

/**
 * Check if process this trigger only.
 *
 * @param triggerWithContext the trigger with its context
 * @param operation current ajax operation
 * @return true if process this trigger only
 */
private boolean isProcessTriggerOnly(final ComponentWithContext triggerWithContext, final AjaxOperation operation) {
    // Target container implies only process the trigger or is Internal Ajax
    if (operation.getTargetContainerId() != null || operation.isInternalAjaxRequest()) {
        return true;
    }
    WComponent trigger = triggerWithContext.getComponent();
    // Check if trigger is a polling AJAX control
    if (trigger instanceof WAjaxControl) {
        // Get user context
        UIContext uic = triggerWithContext.getContext();
        UIContextHolder.pushContext(uic);
        try {
            WAjaxControl ajax = (WAjaxControl) trigger;
            // Is a polling region so only process trigger
            if (ajax.getDelay() > 0) {
                return true;
            }
        } finally {
            UIContextHolder.popContext();
        }
    }
    return false;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) UIContext(com.github.bordertech.wcomponents.UIContext)

Example 59 with WComponent

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

the class AjaxSetupInterceptor method serviceRequest.

/**
 * Setup the AJAX operation details.
 *
 * @param request the request being serviced.
 */
@Override
public void serviceRequest(final Request request) {
    // Get trigger id
    String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
    if (triggerId == null) {
        throw new SystemException("No AJAX trigger id to on request");
    }
    // Find the Component for this trigger
    ComponentWithContext trigger = WebUtilities.getComponentById(triggerId, true);
    if (trigger == null) {
        throw new SystemException("No component found for AJAX trigger " + triggerId + ".");
    }
    WComponent triggerComponent = trigger.getComponent();
    // Check for an internal AJAX request (if client has flagged it as internal)
    boolean internal = request.getParameter(WServlet.AJAX_TRIGGER_INTERNAL_PARAM_NAME) != null;
    AjaxOperation ajaxOperation = null;
    if (internal) {
        if (!(triggerComponent instanceof AjaxInternalTrigger)) {
            throw new SystemException("AJAX trigger [" + triggerId + "] does not support internal actions.");
        }
        // Create internal operation
        ajaxOperation = new AjaxOperation(triggerId);
    } else {
        // Check for a registered AJAX operation
        ajaxOperation = AjaxHelper.getAjaxOperation(triggerId);
        // TODO This is only required until all components start using the Internal param flag
        if (ajaxOperation != null && "GET".equals(request.getMethod()) && triggerComponent instanceof AjaxInternalTrigger) {
            // Create internal operation
            ajaxOperation = new AjaxOperation(triggerId);
        }
    }
    // If no operation registered, check if the trigger supports internal AJAX then assume it is an Internal Action
    if (ajaxOperation == null && trigger.getComponent() instanceof AjaxInternalTrigger) {
        // Create internal operation
        ajaxOperation = new AjaxOperation(triggerId);
    }
    // No Valid operation
    if (ajaxOperation == null) {
        throw new SystemException("No AJAX operation has been registered for trigger " + triggerId + ".");
    }
    // Set current operation
    AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);
    // Process Service Request
    super.serviceRequest(request);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) AjaxInternalTrigger(com.github.bordertech.wcomponents.AjaxInternalTrigger) AjaxOperation(com.github.bordertech.wcomponents.AjaxOperation) SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 60 with WComponent

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

the class DefaultPageShell method getApplicationTitle.

/**
 * Retrieves the application title for the given context. This mess is required due to WWindow essentially existing
 * as a separate UI root. If WWindow is eventually removed, then we can just retrieve the title from the root
 * WApplication.
 *
 * @param uic the context to check.
 * @return the current application title.
 */
private String getApplicationTitle(final UIContext uic) {
    WComponent root = uic.getUI();
    String title = root instanceof WApplication ? ((WApplication) root).getTitle() : null;
    Map<String, String> params = uic.getEnvironment().getHiddenParameters();
    String target = params.get(WWindow.WWINDOW_REQUEST_PARAM_KEY);
    if (target != null) {
        ComponentWithContext targetComp = WebUtilities.getComponentById(target, true);
        if (targetComp != null && targetComp.getComponent() instanceof WWindow) {
            try {
                UIContextHolder.pushContext(targetComp.getContext());
                title = ((WWindow) targetComp.getComponent()).getTitle();
            } finally {
                UIContextHolder.popContext();
            }
        }
    }
    return title == null ? "" : title;
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WApplication(com.github.bordertech.wcomponents.WApplication) WWindow(com.github.bordertech.wcomponents.WWindow) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Aggregations

WComponent (com.github.bordertech.wcomponents.WComponent)107 Test (org.junit.Test)35 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)30 UIContext (com.github.bordertech.wcomponents.UIContext)20 SystemException (com.github.bordertech.wcomponents.util.SystemException)16 DefaultWComponent (com.github.bordertech.wcomponents.DefaultWComponent)14 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)8 WApplication (com.github.bordertech.wcomponents.WApplication)8 WLabel (com.github.bordertech.wcomponents.WLabel)8 AbstractWComponent (com.github.bordertech.wcomponents.AbstractWComponent)7 IOException (java.io.IOException)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 Diagnostic (com.github.bordertech.wcomponents.validation.Diagnostic)5 PrintWriter (java.io.PrintWriter)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Size (com.github.bordertech.wcomponents.Size)4 WRepeater (com.github.bordertech.wcomponents.WRepeater)4 WText (com.github.bordertech.wcomponents.WText)4 WTextField (com.github.bordertech.wcomponents.WTextField)4