Search in sources :

Example 1 with AjaxInternalTrigger

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

Aggregations

AjaxInternalTrigger (com.github.bordertech.wcomponents.AjaxInternalTrigger)1 AjaxOperation (com.github.bordertech.wcomponents.AjaxOperation)1 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1