use of org.apache.wicket.Page in project wicket by apache.
the class PartialPageUpdate method prepareComponent.
/**
* Prepare a single component
*
* @param component
* the component to prepare
* @return wether the component was prepared
*/
protected boolean prepareComponent(Component component) {
if (component.getRenderBodyOnly() == true) {
throw new IllegalStateException("A partial update is not possible for a component that has renderBodyOnly enabled. Component: " + component.toString());
}
component.setOutputMarkupId(true);
// Initialize temporary variables
final Page page = component.findParent(Page.class);
if (page == null) {
// dont throw an exception but just ignore this component, somehow
// it got removed from the page.
LOG.warn("Component '{}' not rendered because it was already removed from page", component);
return false;
}
try {
component.beforeRender();
} catch (RuntimeException e) {
bodyBuffer.reset();
throw e;
}
return true;
}
use of org.apache.wicket.Page in project wicket by apache.
the class AbstractTransformerBehavior method afterRender.
@Override
public void afterRender(final Component component) {
final RequestCycle requestCycle = RequestCycle.get();
try {
BufferedWebResponse tempResponse = (BufferedWebResponse) requestCycle.getResponse();
if (component instanceof Page && originalResponse instanceof WebResponse) {
tempResponse.writeMetaData((WebResponse) originalResponse);
}
// Transform the data
CharSequence output = transform(component, tempResponse.getText());
originalResponse.write(output);
} catch (Exception ex) {
throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex);
} finally {
// Restore the original response object
requestCycle.setResponse(originalResponse);
}
}
use of org.apache.wicket.Page in project wicket by apache.
the class BaseWicketTester method executeListener.
/**
* Simulates processing URL that invokes an {@link IRequestListener} on a component.
*
* After the listener is invoked the page containing the component will be rendered
* (with an optional redirect - depending on {@link RenderStrategy}).
*
* @param component
* @param listener
*/
public void executeListener(final Component component) {
Args.notNull(component, "component");
// there are two ways to do this. RequestCycle could be forced to call the handler
// directly but constructing and parsing the URL increases the chance of triggering bugs
Page page = component.getPage();
PageAndComponentProvider pageAndComponentProvider = new PageAndComponentProvider(page, component);
IRequestHandler handler = null;
if (page.isPageStateless() || (page.isBookmarkable() && page.wasCreatedBookmarkable())) {
handler = new BookmarkableListenerRequestHandler(pageAndComponentProvider);
} else {
handler = new ListenerRequestHandler(pageAndComponentProvider);
}
Url url = urlFor(handler);
request.setUrl(url);
// Process the request
processRequest(request, null);
}
use of org.apache.wicket.Page in project wicket by apache.
the class BaseWicketTester method startComponentInPage.
/**
* Process a component. A web page will be automatically created with the {@code pageMarkup}
* provided. In case {@code pageMarkup} is null, the markup will be automatically created with
* {@link #createPageMarkup(String)}.
* <p>
* <strong>Note</strong>: the component id is set by the user. To reach any of its children use
* this id + their relative path to the component itself. For example if the started component
* has id <em>compId</em> and a Link child component component with id "link" then after
* starting the component you can click it with: <code>tester.clickLink("compId:link")</code>
* </p>
*
* @param <C>
* the type of the component
* @param component
* the component to be tested
* @param pageMarkup
* the markup for the Page that will be automatically created. May be {@code null}.
* @return The component processed
*/
public final <C extends Component> C startComponentInPage(final C component, IMarkupFragment pageMarkup) {
Args.notNull(component, "component");
// Create a page object and assign the markup
Page page = createPage();
if (page == null) {
fail("The automatically created page should not be null.");
}
// Automatically create the page markup if not provided
if (pageMarkup == null) {
String markup = createPageMarkup(component.getId());
if (markup == null) {
fail("The markup for the automatically created page should not be null.");
}
try {
// set a ContainerInfo to be able to use HtmlHeaderContainer so header contribution
// still work. WICKET-3700
ContainerInfo containerInfo = new ContainerInfo(page);
MarkupResourceStream markupResourceStream = new MarkupResourceStream(new StringResourceStream(markup), containerInfo, page.getClass());
MarkupParser markupParser = getApplication().getMarkupSettings().getMarkupFactory().newMarkupParser(markupResourceStream);
pageMarkup = markupParser.parse();
} catch (Exception e) {
String errorMessage = "Error while parsing the markup for the autogenerated page: " + e.getMessage();
log.error(errorMessage, e);
fail(errorMessage);
}
}
if (page instanceof StartComponentInPage) {
((StartComponentInPage) page).setPageMarkup(pageMarkup);
} else {
page.setMarkup(pageMarkup);
}
// Add the child component
page.add(component);
// Preserve 'componentInPage' because #startPage() needs to null-fy it
ComponentInPage oldComponentInPage = componentInPage;
// Process the page
startPage(page);
// Remember the "root" component processes and return it
if (oldComponentInPage != null) {
componentInPage = oldComponentInPage;
} else {
componentInPage = new ComponentInPage();
componentInPage.component = component;
}
return component;
}
use of org.apache.wicket.Page in project wicket by apache.
the class BaseWicketTester method isRenderedPage.
/**
* Asserts the last rendered <code>Page</code> class.
*
* @param <C>
* @param expectedRenderedPageClass
* expected class of last rendered page
* @return a <code>Result</code>
*/
public <C extends Page> Result isRenderedPage(Class<C> expectedRenderedPageClass) {
Args.notNull(expectedRenderedPageClass, "expectedRenderedPageClass");
Page page = getLastRenderedPage();
if (page == null) {
return Result.fail("page was null");
}
if (!expectedRenderedPageClass.isAssignableFrom(page.getClass())) {
return Result.fail(String.format("classes not the same, expected '%s', current '%s'", expectedRenderedPageClass, page.getClass()));
}
return Result.pass();
}
Aggregations