use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class BaseWicketTester method startPage.
/**
* Renders the page specified by given {@link IPageProvider}. After render the page instance can
* be retrieved using {@link #getLastRenderedPage()} and the rendered document will be available
* in {@link #getLastResponse()}.
*
* Depending on {@link RenderStrategy} invoking this method can mean that a redirect will happen
* before the actual render.
*
* @param pageProvider
* @return last rendered page
*/
public Page startPage(final IPageProvider pageProvider) {
// should be null for Pages
componentInPage = null;
// prepare request
request.setURL(request.getContextPath() + request.getServletPath() + "/");
IRequestHandler handler = new RenderPageRequestHandler(pageProvider);
// process request
processRequest(request, handler);
// The page rendered
return getLastRenderedPage();
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class AbstractBookmarkableMapper method processBookmarkable.
/**
* Creates a {@code IRequestHandler} that processes a bookmarkable request.
*
* @param pageClass
* @param pageParameters
* @return a {@code IRequestHandler} capable of processing the bookmarkable request.
*/
protected IRequestHandler processBookmarkable(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters) {
PageProvider provider = new PageProvider(pageClass, pageParameters);
provider.setPageSource(getContext());
return new RenderPageRequestHandler(provider);
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class AbstractBookmarkableMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
// eliminate the need for IRequestHandlerDelegate
while (requestHandler instanceof IRequestHandlerDelegate) {
requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
}
if (requestHandler instanceof BookmarkablePageRequestHandler) {
// simple bookmarkable URL with no page instance information
BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else if (requestHandler instanceof RenderPageRequestHandler) {
// possibly hybrid URL - bookmarkable URL with page instance information
// but only allowed if the page was created by bookmarkable URL
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
if (handler.getPageProvider().isNewPageInstance()) {
// no existing page instance available, don't bother creating new page instance
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
}
IRequestablePage page = handler.getPage();
if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
PageInfo info = getPageInfo(handler);
PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else {
return null;
}
} else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
// request listener URL with page class information
BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
Class<? extends IRequestablePage> pageClass = handler.getPageClass();
if (!checkPageClass(pageClass)) {
return null;
}
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = handler.getRenderCount();
}
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
return buildUrl(urlInfo);
}
return null;
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class AjaxRequestHandler method respond.
/**
* @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
*/
@Override
public final void respond(final IRequestCycle requestCycle) {
final RequestCycle rc = (RequestCycle) requestCycle;
final WebResponse response = (WebResponse) requestCycle.getResponse();
if (shouldRedirectToPage(requestCycle)) {
// the page itself has been added to the request target, we simply issue a redirect
// back to the page
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
final String url = rc.urlFor(handler).toString();
response.sendRedirect(url);
return;
}
respondersFrozen = true;
for (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
update.setContentType(response, encoding);
// Make sure it is not cached by a client
response.disableCaching();
final StringResponse bodyResponse = new StringResponse();
update.writeTo(bodyResponse, encoding);
CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
response.write(filteredResponse);
}
use of org.apache.wicket.core.request.handler.RenderPageRequestHandler in project wicket by apache.
the class BookmarkableMapperTest method encode5.
/**
*/
@Test
public void encode5() {
MockPage page = new MockPage(15);
page.getPageParameters().set(0, "i1");
page.getPageParameters().set(1, "i2");
page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
page.setCreatedBookmarkable(false);
IPageProvider provider = new PageProvider(page);
IRequestHandler handler = new RenderPageRequestHandler(provider);
Url url = encoder.mapHandler(handler);
// never allow bookmarkable render url for page that has not been
// created by bookmarkable
// URL
assertNull(url);
}
Aggregations