List of usage examples for org.apache.wicket.response StringResponse StringResponse
public StringResponse()
From source file:jp.javelindev.wicket.ajaxlist.AjaxListPage.java
License:Apache License
public AjaxListPage(PageParameters parameters) { super(parameters); final RepeatingView view = new RepeatingView("item"); add(view);/* w w w. j av a2 s. c om*/ Label defaultLabel = new Label(view.newChildId(), "test"); defaultLabel.setOutputMarkupId(true); view.add(defaultLabel); add(new AjaxLink<Void>("addNew") { private static final long serialVersionUID = 1L; @Override public void onClick(AjaxRequestTarget target) { Label newLabel = new Label(view.newChildId(), new SimpleDateFormat("HH:mm:ss").format(new Date())); newLabel.setOutputMarkupId(true); view.add(newLabel); Response bodyResonse = new StringResponse(); Response originalResponse = getResponse(); getRequestCycle().setResponse(bodyResonse); newLabel.render(); String componentString = bodyResonse.toString(); LOGGER.info("label: {}", componentString); getRequestCycle().setResponse(originalResponse); target.appendJavaScript("$('#viewContainer').append('" + componentString + "')"); } }); add(new HeaderResponseFilteredResponseContainer("footerJS", "footerJS")); }
From source file:name.martingeisse.wicket.component.tree.JsTree.java
License:Open Source License
private String renderToString() { // prepare string response final RequestCycle requestCycle = RequestCycle.get(); final Response oldResponse = requestCycle.getResponse(); final StringResponse newResponse = new StringResponse(); requestCycle.setResponse(newResponse); // prepare rendering (I know, this calls internal Wicket API ...) Page page = getPage();// www . ja v a2 s . co m page.startComponentRender(this); try { prepareForRender(); } catch (RuntimeException e) { try { afterRender(); } catch (RuntimeException e2) { } RequestCycle.get().setResponse(oldResponse); throw e; } // render the component try { render(); } catch (RuntimeException e) { RequestCycle.get().setResponse(oldResponse); throw e; } // cleanup render state page.endComponentRender(this); // restore original response requestCycle.setResponse(oldResponse); return newResponse.toString(); }
From source file:name.martingeisse.wicket.util.json.JsonEncodingContainer.java
License:Open Source License
@Override protected void onRender() { Response previousResponse = getResponse(); StringResponse fakeResponse = new StringResponse(); getRequestCycle().setResponse(fakeResponse); super.onRender(); previousResponse.write(JavascriptAssemblerUtil.formatStringLiteral(fakeResponse.toString())); getRequestCycle().setResponse(previousResponse); }
From source file:org.hippoecm.frontend.service.render.AbstractRenderService.java
License:Apache License
@Override public void onComponentTagBody(MarkupStream markupStream, final ComponentTag openTag) { int beginOfBodyIndex = markupStream.getCurrentIndex(); Response response = new StringResponse(); RequestCycle requestCycle = getRequestCycle(); Response webResponse = requestCycle.setResponse(response); try {//from w ww .jav a 2s. c o m super.onComponentTagBody(markupStream, openTag); webResponse.write(response.toString()); } catch (WicketRuntimeException ex) { log.error("runtime plugin failure", ex); // this is a plugin, don't let the entire UI fail because of it failing markupStream.setCurrentIndex(beginOfBodyIndex); markupStream.skipToMatchingCloseTag(openTag); } finally { requestCycle.setResponse(webResponse); } }
From source file:sf.wicklet.gwt.server.ajax.impl.GwtAjaxWickletTarget.java
License:Apache License
/** * @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle) *///from w w w . ja v a 2 s . c o m @Override public final void respond(final IRequestCycle requestCycle) { final RequestCycle rc = (RequestCycle) requestCycle; final WebResponse response = (WebResponse) requestCycle.getResponse(); if (errorResponse(response)) { return; } if (responseObject.containsPage()) { // the page itself has been added to the request target, we simply issue a redirect // back to the page final IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page)); final String url = rc.urlFor(handler).toString(); response.sendRedirect(url); return; } respondersFrozen = true; for (final ITargetRespondListener listener : respondListeners) { listener.onTargetRespond(this); } final Application app = page.getApplication(); page.send(app, Broadcast.BREADTH, this); // Determine encoding final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding(); // Set content type based on markup type for page responseObject.setContentType(response, encoding); // Make sure it is not cached by a client response.disableCaching(); try { final StringResponse bodyResponse = new StringResponse(); responseObject.writeTo(bodyResponse, encoding); final CharSequence filteredResponse = invokeResponseFilters(bodyResponse); response.write(filteredResponse); } finally { // restore the original response rc.setResponse(response); } }