/** * @return {@code true} if the current Input is also the current Ajax trigger. */ public final boolean isCurrentAjaxTrigger() { return AjaxHelper.isCurrentAjaxTrigger(this); }
/** * {@inheritDoc} */ @Override public void paint(final RenderContext renderContext) { try { super.paint(renderContext); } finally { AjaxHelper.clearCurrentOperationDetails(); } } }
/** * @param trigger the AJAX trigger to check * @return true if this is the current AJAX trigger */ public static boolean isCurrentAjaxTrigger(final WComponent trigger) { if (trigger == null) { return false; } AjaxOperation operation = AjaxHelper.getCurrentOperation(); return operation != null && operation.getTriggerId().equals(trigger.getId()); }
AjaxHelper.setCurrentOperationDetails(operation, null); getAjaxFilter()); } finally { AjaxHelper.clearCurrentOperationDetails();
} else { ajaxOperation = AjaxHelper.getAjaxOperation(triggerId); AjaxHelper.setCurrentOperationDetails(ajaxOperation, trigger);
/** * Override preparePaintComponent to register an AJAX operation if this button is AJAX enabled. * * @param request the request being responded to */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); UIContext uic = UIContextHolder.getCurrent(); if (isAjax() && uic.getUI() != null) { AjaxTarget target = getAjaxTarget(); AjaxHelper.registerComponent(target.getId(), getId()); } }
String triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME); AjaxOperation ajaxOperation = AjaxHelper.getCurrentOperation(); if (ajaxOperation == null) { throw new IllegalStateException( ComponentWithContext triggerWithContext = AjaxHelper.getCurrentTriggerAndContext(); if (triggerWithContext == null) { throw new IllegalStateException(
/** * A convenience method to create an AJAX operation. * * @param target the component to target */ private void setActiveAjaxOperation(final WComponent target) { AjaxOperation operation = new AjaxOperation(target.getId(), target.getId()); AjaxHelper.setCurrentOperationDetails(operation, new ComponentWithContext(target, UIContextHolder.getCurrent())); } }
@Test public void testPreparePaintComponent() { WApplication app = new WApplication(); AjaxTrigger trigger = new WButton(); AjaxTarget target = new WPanel(); WAjaxControl control = new WAjaxControl(trigger, target); app.add(control); app.add(trigger); app.add(target); app.setLocked(true); UIContext uic = createUIContext(); uic.setUI(app); setActiveContext(uic); MockRequest req = new MockRequest(); control.handleRequest(req); control.preparePaint(req); AjaxOperation ajaxOperation = AjaxHelper.getAjaxOperation(trigger.getId()); Assert.assertNotNull("Ajax operation should have been registered", ajaxOperation); Assert.assertEquals("Incorrect ajax operation trigger id", trigger.getId(), ajaxOperation. getTriggerId()); Assert.assertEquals("Incorrect ajax operation targets", target.getId(), ajaxOperation. getTargets().get(0)); }
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext(); if (trigger == null) { throw new IllegalStateException(
/** * Retrieves the AjaxOperation that has been registered for the given trigger. This method will return null if there * is no corresponding operation registered. * * @param triggerId the trigger id. * @return the AjaxOperation corresponding to the trigger id. */ public static AjaxOperation getAjaxOperation(final String triggerId) { Map<String, AjaxOperation> operations = getRegisteredOperations(); return operations == null ? null : operations.get(triggerId); }
/** * Clear all the registered AJAX operations. * * @param request the request being serviced. */ @Override public void serviceRequest(final Request request) { // Clear all the registered AJAX operations AjaxHelper.clearAllRegisteredOperations(); // Process Service Request super.serviceRequest(request); } }
AjaxHelper.setCurrentOperationDetails(new AjaxOperation("X", "Z"), null); AjaxHelper.setCurrentOperationDetails(new AjaxOperation(link.getId(), link.getId()), null); } finally { AjaxHelper.clearCurrentOperationDetails();
/** * Override preparePaintComponent to register an AJAX operation if this list is AJAX enabled. * * @param request the request being responded to. */ @Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (isAjax() && UIContextHolder.getCurrent().getUI() != null) { AjaxTarget target = getAjaxTarget(); AjaxHelper.registerComponent(target.getId(), getId()); } String cacheKey = getListCacheKey(); if (cacheKey != null) { LookupTableHelper.registerList(cacheKey, request); } }
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext(); if (trigger == null) { throw new SystemException("No context available for trigger " + operation.getTriggerId());
/** * @return true if polling and is the current AJAX trigger. */ protected boolean isPollingTrigger() { return isPolling() && AjaxHelper.isCurrentAjaxTrigger(ajaxPolling); }
try { AjaxHelper.setCurrentOperationDetails(new AjaxOperation("testid", "X"), null); tab.preparePaintComponent(request); Assert.assertTrue("content should be visible", component.isVisible()); } finally { AjaxHelper.clearCurrentOperationDetails(); try { AjaxHelper.setCurrentOperationDetails(new AjaxOperation(tab.getId(), "X"), null); tab.preparePaintComponent(request); Assert.assertTrue("content should have been set to visible", component.isVisible()); } finally { AjaxHelper.clearCurrentOperationDetails();
/** * Indicates whether the dialog is currently the target of an AJAX operation. * * @return true if the dialog is currently AJAX targeted, otherwise false. */ public final boolean isAjaxTargeted() { // If the AJAX target is within the dialog, it should be visible. AjaxOperation operation = AjaxHelper.getCurrentOperation(); if (operation == null) { return false; } String dialogId = getId(); String containerId = operation.getTargetContainerId(); if (containerId != null && containerId.startsWith(dialogId)) { // target is the dialog, or somewhere within the dialog return true; } if (operation.getTargets() != null && UIContextHolder.getCurrent() != null) { for (String targetId : operation.getTargets()) { if (targetId.startsWith(dialogId)) { return true; } } } return false; }
AjaxHelper.registerComponent(app.target.getId(), app.trigger.getId()); request.setParameter(WServlet.AJAX_TRIGGER_PARAM_NAME, app.trigger.getId()); request.setParameter(Environment.STEP_VARIABLE, String.valueOf(clientStep));
@After public void resetAjaxOperation() { AjaxHelper.clearCurrentOperationDetails(); }