@Inject private Request request; @OnEvent(EventConstants.SUCCESS) Object formSubmitted(){ //return zone content only if AJAX request, page otherwise if (request.isXHR()) { return myZone.getBody(); } else { return this; } }
/** * Returns true for normal, non-XHR requests. Links (to the failure page, or to root page) are only * presented if showActions is true. */ public boolean isShowActions() { return !request.isXHR(); }
public boolean isXHR() { return request.isXHR(); }
public void handle(ComponentEventRequestParameters parameters, ComponentEventRequestHandler handler) throws IOException { ComponentEventRequestHandler next = request.isXHR() ? ajaxHandler : handler; next.handle(parameters); }
Object onActivate() { if (request.isXHR()) { message = "Redirected from XHR"; return this; } return null; }
/** * Repaging event handler. */ boolean onAction(int newPage) { // TODO: Validate newPage in range currentPage = newPage; if (request.isXHR()) { resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, null, null); } return true; // abort event } }
protected final void train_isXHR(Request request, boolean isXHR) { expect(request.isXHR()).andReturn(isXHR).atLeastOnce(); }
/** * Normal, non-Ajax event handler. */ boolean onSort(String columnId) { gridModel.getSortModel().updateSort(columnId); if (request.isXHR()) { resources.triggerEvent(InternalConstants.GRID_INPLACE_UPDATE, null, null); } return true; }
public void alert(Duration duration, Severity severity, String message, boolean markup) { final Alert alert = new Alert(duration, severity, message, markup); if (request.isXHR()) { addCallbackForAlert(alert); } // Add it to the storage; this is always done, even in an Ajax request, because we may end up // redirecting to a new page, rather than doing a partial page update on the current page ... in which // case we need the alerts stored persistently until we render the new page. getAlertStorage().add(alert); }
public void alert(Duration duration, Severity severity, String message) { final Alert alert = new Alert(duration, severity, message); if (request.isXHR()) { addCallbackForAlert(alert); } // Add it to the storage; this is always done, even in an Ajax request, because we may end up // redirecting to a new page, rather than doing a partial page update on the current page ... in which // case we need the alerts stored persistently until we render the new page. getAlertStorage().add(alert); }
public void handleComponentEvent(final ComponentEventRequestParameters parameters, final ComponentRequestHandler handler) throws IOException { String componentId = parameters.getNestedComponentId().equals("") ? parameters.getContainingPageName() : parameters.getContainingPageName() + ":" + parameters.getNestedComponentId(); tracker.perform(String.format("Handling %s '%s' component event request for %s.", request.isXHR() ? "Ajax" : "traditional", parameters.getEventType(), componentId), new IOOperation<Void>() { public Void perform() throws IOException { handler.handleComponentEvent(parameters); return null; } }); }
: linkSource.createPageRenderLink(page.toString(), false, exceptionContext); if (request.isXHR())
Object onDismiss(@RequestParameter(value = "id", allowBlank = true) Long alertId) { // If the alert was created inside an Ajax request and AlertStorage did not previously // exist, it can be null when the dismiss event comes up from the client. if (storage != null) { if (alertId != null) { storage.dismiss(alertId); } else { storage.dismissAll(); } } // See TAP5-1941 if (!request.isXHR()) { return true; } return new JSONObject(); }
@Test(dataProvider = "xhr_inputs") public void is_xhr_request(String headerValue, boolean expected) { HttpServletRequest sr = mockHttpServletRequest(); expect(sr.getHeader(RequestImpl.REQUESTED_WITH_HEADER)).andReturn(headerValue); replay(); Request request = new RequestImpl(sr, CHARSET, null); assertEquals(request.isXHR(), expected); verify(); }
@Log public Object onValueChangedFromSelectValue1(SelectObj selectObj, Integer integer, RetentionPolicy retentionPolicy) { final String suffix = String.format(", number %03d, retention policy %s", integer, retentionPolicy); List<SelectObj> select2List = new ArrayList(); select2List.add(new SelectObj(4, "4 post ajax" + suffix)); select2List.add(new SelectObj(5, "5 post ajax" + suffix)); select2List.add(new SelectObj(6, "6 post ajax" + suffix)); select2List.add(new SelectObj(7, "7 post ajax" + suffix)); select2Model = new SelectObjModel(select2List); if (request.isXHR()) { return new MultiZoneUpdate("select1ValueZone", select1ValueZone.getBody()).add("select2ValueZone", select2ValueZone.getBody()); } else { return this; } }
if (request.isXHR())
/** * Render the upload tags. * * @param writer * Writer to output markup */ protected void beginRender(MarkupWriter writer) { formSupport.setEncodingType(MULTIPART_ENCTYPE); writer.element("input", "type", "file", "name", getControlName(), "id", getClientId(), "class", cssClass); validate.render(writer); resources.renderInformalParameters(writer); decorateInsideField(); // TAPESTRY-2453 if (request.isXHR()) { javaScriptSupport.require("t5/core/injected-upload").with(getClientId()); } }
/** * Render the upload tags. * * @param writer * Writer to output markup */ protected void beginRender(MarkupWriter writer) { formSupport.setEncodingType(MULTIPART_ENCTYPE); writer.element("input", "type", "file", "name", getControlName(), "id", getClientId(), "class", cssClass); validate.render(writer); resources.renderInformalParameters(writer); decorateInsideField(); // TAPESTRY-2453 if (request.isXHR()) { javaScriptSupport.require("t5/core/injected-upload").with(getClientId()); } }
@Test public void handleRequestExceptionWithConfiguredPage() throws IOException { train_resolvePageClassNameToPageName(componentClassResolver, MyPage.class.getName(), "mypage"); Link link = mockLink(); expect(linkSource.createPageRenderLink("mypage", false, new Object[]{"accesscontrol"})).andReturn(link); expect(request.isXHR()).andReturn(false); response.sendRedirect(link); EasyMock.expectLastCall(); replay(); // also test unwrapping TapestryExceptions exceptionHandler.handleRequestException(new OperationException(new RenderQueueException( "renderqueue", new Object[0], new TapestryException("tapestryexception", new AccessControlException("No permission"))), new String[0])); }
if (tracker.getHasErrors() && !request.isXHR())