Search in sources :

Example 26 with WAjaxControl

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

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

the class WAjaxControlRenderer method doRender.

/**
 * Paints the given AjaxControl.
 *
 * @param component the AjaxControl to paint
 * @param renderContext the RenderContext to paint to
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WAjaxControl ajaxControl = (WAjaxControl) component;
    XmlStringBuilder xml = renderContext.getWriter();
    WComponent trigger = ajaxControl.getTrigger() == null ? ajaxControl : ajaxControl.getTrigger();
    int delay = ajaxControl.getDelay();
    if (ajaxControl.getTargets() == null || ajaxControl.getTargets().isEmpty()) {
        return;
    }
    // Start tag
    xml.appendTagOpen("ui:ajaxtrigger");
    xml.appendAttribute("triggerId", trigger.getId());
    xml.appendOptionalAttribute("loadOnce", ajaxControl.isLoadOnce(), "true");
    xml.appendOptionalAttribute("delay", delay > 0, delay);
    xml.appendClose();
    // Targets
    for (AjaxTarget target : ajaxControl.getTargets()) {
        xml.appendTagOpen("ui:ajaxtargetid");
        xml.appendAttribute("targetId", target.getId());
        xml.appendEnd();
    }
    // End tag
    xml.appendEndTag("ui:ajaxtrigger");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WAjaxControl(com.github.bordertech.wcomponents.WAjaxControl) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder) AjaxTarget(com.github.bordertech.wcomponents.AjaxTarget)

Aggregations

WAjaxControl (com.github.bordertech.wcomponents.WAjaxControl)27 WButton (com.github.bordertech.wcomponents.WButton)18 ActionEvent (com.github.bordertech.wcomponents.ActionEvent)16 Action (com.github.bordertech.wcomponents.Action)15 WHeading (com.github.bordertech.wcomponents.WHeading)13 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)10 WPanel (com.github.bordertech.wcomponents.WPanel)8 Margin (com.github.bordertech.wcomponents.Margin)6 WTextField (com.github.bordertech.wcomponents.WTextField)6 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)5 WLabel (com.github.bordertech.wcomponents.WLabel)5 AjaxTarget (com.github.bordertech.wcomponents.AjaxTarget)4 ExplanatoryText (com.github.bordertech.wcomponents.examples.common.ExplanatoryText)4 ValidatingAction (com.github.bordertech.wcomponents.validation.ValidatingAction)4 WRadioButtonSelect (com.github.bordertech.wcomponents.WRadioButtonSelect)3 Equal (com.github.bordertech.wcomponents.subordinate.Equal)3 Rule (com.github.bordertech.wcomponents.subordinate.Rule)3 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)3 ArrayList (java.util.ArrayList)3 WComponent (com.github.bordertech.wcomponents.WComponent)2