Search in sources :

Example 16 with ComponentWithContext

use of com.github.bordertech.wcomponents.ComponentWithContext 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 17 with ComponentWithContext

use of com.github.bordertech.wcomponents.ComponentWithContext 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)

Example 18 with ComponentWithContext

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

the class TargetableInterceptor method preparePaint.

/**
 * {@inheritDoc}
 */
@Override
public void preparePaint(final Request request) {
    ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
    if (target == null) {
        throw new SystemException("No target component found for id " + targetId);
    }
    UIContextHolder.pushContext(target.getContext());
    try {
        super.preparePaint(request);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 19 with ComponentWithContext

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

the class TargetableInterceptor method serviceRequest.

/**
 * {@inheritDoc}
 */
@Override
public void serviceRequest(final Request request) {
    // Check if this is a targeted request
    targetId = request.getParameter(Environment.TARGET_ID);
    if (targetId == null) {
        throw new SystemException("No target id request parameter");
    }
    ComponentWithContext target = WebUtilities.getComponentById(targetId, true);
    if (target == null) {
        throw new SystemException("No target component found for id " + targetId);
    }
    // go straight to the target component.
    attachUI(target.getComponent());
    UIContextHolder.pushContext(target.getContext());
    try {
        super.serviceRequest(request);
    } finally {
        UIContextHolder.popContext();
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Example 20 with ComponentWithContext

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

the class WWindowInterceptor method serviceRequest.

/**
 * Temporarily replaces the environment while the request is being handled.
 *
 * @param request the request being responded to.
 */
@Override
public void serviceRequest(final Request request) {
    // Get window id off the request
    windowId = request.getParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY);
    if (windowId == null) {
        super.serviceRequest(request);
    } else {
        // Get the window component
        ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
        if (target == null) {
            throw new SystemException("No window component for id " + windowId);
        }
        // Setup the Environment on the context
        UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
        Environment originalEnvironment = uic.getEnvironment();
        uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
        if (attachWindow) {
            attachUI(target.getComponent());
        }
        UIContextHolder.pushContext(target.getContext());
        try {
            super.serviceRequest(request);
        } finally {
            uic.setEnvironment(originalEnvironment);
            UIContextHolder.popContext();
        }
    }
}
Also used : SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) Environment(com.github.bordertech.wcomponents.Environment) ComponentWithContext(com.github.bordertech.wcomponents.ComponentWithContext)

Aggregations

ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)22 UIContext (com.github.bordertech.wcomponents.UIContext)10 SystemException (com.github.bordertech.wcomponents.util.SystemException)10 WComponent (com.github.bordertech.wcomponents.WComponent)8 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)3 Environment (com.github.bordertech.wcomponents.Environment)3 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 ArrayList (java.util.ArrayList)3 VisitorResult (com.github.bordertech.wcomponents.util.WComponentTreeVisitor.VisitorResult)2 FindComponentByIdVisitor (com.github.bordertech.wcomponents.util.visitor.FindComponentByIdVisitor)2 Test (org.junit.Test)2 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)1 AjaxInternalTrigger (com.github.bordertech.wcomponents.AjaxInternalTrigger)1 WApplication (com.github.bordertech.wcomponents.WApplication)1 WAudio (com.github.bordertech.wcomponents.WAudio)1 WContent (com.github.bordertech.wcomponents.WContent)1 WImage (com.github.bordertech.wcomponents.WImage)1 WVideo (com.github.bordertech.wcomponents.WVideo)1 WWindow (com.github.bordertech.wcomponents.WWindow)1