use of org.apache.wicket.Page in project wicket by apache.
the class PartialPageUpdate method detach.
/**
* Detaches the page if at least one of its components was updated.
*
* @param requestCycle
* the current request cycle
*/
public void detach(IRequestCycle requestCycle) {
Iterator<Component> iterator = markupIdToComponent.values().iterator();
while (iterator.hasNext()) {
final Component component = iterator.next();
final Page parentPage = component.findParent(Page.class);
if (parentPage != null) {
parentPage.detach();
break;
}
}
}
use of org.apache.wicket.Page in project wicket by apache.
the class AbstractWebSocketProcessor method broadcastMessage.
/**
* 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() || message instanceof ClosedMessage)) {
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;
}
IPageManager pageManager = session.getPageManager();
Page page = getPage(pageManager);
if (page != null) {
WebSocketRequestHandler requestHandler = webSocketSettings.newWebSocketRequestHandler(page, connection);
WebSocketPayload payload = createEventPayload(message, requestHandler);
if (!(message instanceof ConnectedMessage || message instanceof ClosedMessage || message instanceof AbortedMessage)) {
requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
}
IRequestHandler broadcastingHandler = new WebSocketMessageBroadcastHandler(pageId, resourceName, payload);
requestMapper.setHandler(broadcastingHandler);
requestCycle.processRequestAndDetach();
} else {
LOG.debug("Page with id '{}' has been expired. No message will be broadcast!", pageId);
}
} catch (Exception x) {
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);
}
}
use of org.apache.wicket.Page in project wicket by apache.
the class ListenerRequestHandler method internalInvoke.
private void internalInvoke(final IRequestCycle requestCycle, RedirectPolicy policy, boolean ajax, final Component component, final Object target) {
// save a reference to the page because the component can be removed
// during the invocation of the listener and thus lose its parent
Page page = component.getPage();
// initialization is required for stateless pages
if (!page.isInitialized()) {
page.internalInitialize();
}
IRequestListener requestListener = (IRequestListener) target;
if (requestListener.rendersPage() && !ajax) {
// schedule page render after current request handler is done. this can be
// overridden during invocation of listener
// method (i.e. by calling RequestCycle#setResponsePage)
requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
}
requestListener.onRequest();
}
use of org.apache.wicket.Page in project wicket by apache.
the class ListenerRequestHandler method respond.
@Override
public void respond(final IRequestCycle requestCycle) {
final IRequestablePage page = getPage();
final boolean freshPage = pageComponentProvider.doesProvideNewPage();
final boolean isAjax = ((WebRequest) requestCycle.getRequest()).isAjax();
IRequestableComponent component;
try {
component = getComponent();
} catch (ComponentNotFoundException e) {
// either the page is stateless and the component we are looking for is not added in the
// constructor
// or the page is stateful+stale and a new instances was created by pageprovider
// we denote this by setting component to null
component = null;
}
if ((component == null && !freshPage) || (component != null && component.getPage() != page)) {
throw new ComponentNotFoundException("Component '" + getComponentPath() + "' has been removed from page.");
}
if (page instanceof Page) {
// initialize the page to be able to check whether it is stateless
((Page) page).internalInitialize();
}
RedirectPolicy policy = page.isPageStateless() ? RedirectPolicy.NEVER_REDIRECT : RedirectPolicy.AUTO_REDIRECT;
boolean blockIfExpired = component != null && !component.canCallListenerAfterExpiry();
boolean lateComponent = component == null && freshPage;
if ((pageComponentProvider.wasExpired() && blockIfExpired) || lateComponent) {
if (LOG.isDebugEnabled()) {
LOG.debug("An IRequestListener was called but its page/component({}) couldn't be resolved. " + "Scheduling re-create of the page and ignoring the listener interface...", getComponentPath());
}
if (isAjax) {
policy = RedirectPolicy.ALWAYS_REDIRECT;
}
requestCycle.scheduleRequestHandlerAfterCurrent(new RenderPageRequestHandler(new PageProvider(page), policy));
return;
}
invokeListener(requestCycle, policy, isAjax);
}
use of org.apache.wicket.Page in project wicket by apache.
the class PageAndComponentProvider method getComponent.
@Override
public IRequestableComponent getComponent() {
if (component == null) {
IRequestablePage page = getPageInstance();
component = page != null ? page.get(componentPath) : null;
if (component == null) {
// make sure this page instance was just created so the page can be stateless
if (page.isPageStateless()) {
Page p = (Page) page;
p.internalInitialize();
// preparation of feedbacks is delayed into the render phase
try (FeedbackDelay delay = new FeedbackDelay(p.getRequestCycle())) {
p.beforeRender();
p.markRendering(false);
// note: no invocation of delay.onBeforeRender()
}
component = page.get(componentPath);
}
}
}
if (component == null) {
throw new ComponentNotFoundException("Could not find component '" + componentPath + "' on page '" + getPageClass());
}
return component;
}
Aggregations