Java Code Examples for org.apache.wicket.request.cycle.RequestCycle#scheduleRequestHandlerAfterCurrent()
The following examples show how to use
org.apache.wicket.request.cycle.RequestCycle#scheduleRequestHandlerAfterCurrent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChartPanel.java From inception with Apache License 2.0 | 7 votes |
@Override public void onRequest() { RequestCycle requestCycle = RequestCycle.get(); LearningCurve learningCurve = getModelObject(); try { String json = addLearningCurve(learningCurve); // return the chart data back to the UI with the JSON. JSON define te learning // curves and the xaxis requestCycle.scheduleRequestHandlerAfterCurrent( new TextRequestHandler("application/json", "UTF-8", json)); } catch (JsonProcessingException e) { LOG.error(e.toString(), e); } }
Example 2
Source File: PFAutoCompleteBehavior.java From projectforge-webapp with GNU General Public License v3.0 | 7 votes |
protected final void onRequest(final String val, final RequestCycle requestCycle) { // final PageParameters pageParameters = new PageParameters(requestCycle.getRequest().getParameterMap()); final List<T> choices = getChoices(val); final MyJsonBuilder builder = new MyJsonBuilder(); final String json = builder.append(choices).getAsString(); requestCycle.scheduleRequestHandlerAfterCurrent(new TextRequestHandler("application/json", "utf-8", json)); /* * IRequestTarget target = new IRequestTarget() { * * public void respond(RequestCycle requestCycle) { * * WebResponse r = (WebResponse) requestCycle.getResponse(); // Determine encoding final String encoding = * Application.get().getRequestCycleSettings().getResponseRequestEncoding(); r.setCharacterEncoding(encoding); * r.setContentType("application/json"); // Make sure it is not cached by a r.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); * r.setHeader("Cache-Control", "no-cache, must-revalidate"); r.setHeader("Pragma", "no-cache"); * * final List<T> choices = getChoices(val); renderer.renderHeader(r); renderer.render(JsonBuilder.buildRows(false, choices), r, val); * renderer.renderFooter(r); } * * public void detach(RequestCycle requestCycle) { } }; requestCycle.setRequestTarget(target); */ }
Example 3
Source File: AbstractWebSocketProcessor.java From onedev with MIT License | 4 votes |
/** * Exports the Wicket thread locals and broadcasts the received message from the client to all * interested components and behaviors in the page with id {@code #pageId} * <p> * Note: ConnectedMessage and ClosedMessage messages are notification-only. I.e. whatever the * components/behaviors write in the WebSocketRequestHandler will be ignored because the protocol * doesn't expect response from the user. * </p> * * @param message * the message to broadcast */ public final void broadcastMessage(final IWebSocketMessage message) { IKey key = getRegistryKey(); IWebSocketConnection connection = connectionRegistry.getConnection(application, sessionId, key); if (connection != null && connection.isOpen()) { Application oldApplication = ThreadContext.getApplication(); Session oldSession = ThreadContext.getSession(); RequestCycle oldRequestCycle = ThreadContext.getRequestCycle(); WebResponse webResponse = webSocketSettings.newWebSocketResponse(connection); try { WebSocketRequestMapper requestMapper = new WebSocketRequestMapper(application.getRootRequestMapper()); RequestCycle requestCycle = createRequestCycle(requestMapper, webResponse); ThreadContext.setRequestCycle(requestCycle); ThreadContext.setApplication(application); Session session; if (oldSession == null || message instanceof IWebSocketPushMessage) { ISessionStore sessionStore = application.getSessionStore(); session = sessionStore.lookup(webRequest); ThreadContext.setSession(session); } else { session = oldSession; } // Session is null if we copy the url with jsessionid to a new browser window if (session != null) { IPageManager pageManager = session.getPageManager(); Page page = getPage(pageManager); if (page != null) { WebSocketRequestHandler requestHandler = webSocketSettings.newWebSocketRequestHandler(page, connection); @SuppressWarnings("rawtypes") WebSocketPayload payload = createEventPayload(message, requestHandler); if (!(message instanceof ConnectedMessage || message instanceof ClosedMessage)) { requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler); } IRequestHandler broadcastingHandler = new WebSocketMessageBroadcastHandler(pageId, resourceName, payload); requestMapper.setHandler(broadcastingHandler); requestCycle.processRequestAndDetach(); } } } catch (Exception x) { try { connection.sendMessage(WebSocketManager.ERROR_MESSAGE); } catch (IOException e1) { } LOG.error("An error occurred during processing of a WebSocket message", x); } finally { try { webResponse.close(); } finally { ThreadContext.setApplication(oldApplication); ThreadContext.setRequestCycle(oldRequestCycle); ThreadContext.setSession(oldSession); } } } else { LOG.debug("Either there is no connection({}) or it is closed.", connection); } }