Search in sources :

Example 56 with Page

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;
}
Also used : Page(org.apache.wicket.Page)

Example 57 with Page

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);
    }
}
Also used : BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) BufferedWebResponse(org.apache.wicket.protocol.http.BufferedWebResponse) WebResponse(org.apache.wicket.request.http.WebResponse) RequestCycle(org.apache.wicket.request.cycle.RequestCycle) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) Page(org.apache.wicket.Page) WicketRuntimeException(org.apache.wicket.WicketRuntimeException)

Example 58 with Page

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);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url)

Example 59 with Page

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;
}
Also used : ContainerInfo(org.apache.wicket.markup.ContainerInfo) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) MarkupResourceStream(org.apache.wicket.markup.MarkupResourceStream) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) IOException(java.io.IOException) ParseException(java.text.ParseException) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) MarkupParser(org.apache.wicket.markup.MarkupParser)

Example 60 with Page

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();
}
Also used : WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page)

Aggregations

Page (org.apache.wicket.Page)94 Test (org.junit.Test)50 WebPage (org.apache.wicket.markup.html.WebPage)22 Component (org.apache.wicket.Component)11 AjaxLink (org.apache.wicket.ajax.markup.html.AjaxLink)7 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)7 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)6 IRequestHandler (org.apache.wicket.request.IRequestHandler)6 RequestCycle (org.apache.wicket.request.cycle.RequestCycle)6 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)6 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)5 IMarkupFragment (org.apache.wicket.markup.IMarkupFragment)5 DummyPage (org.apache.wicket.resource.DummyPage)5 ArrayList (java.util.ArrayList)4 AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)4 AccessDeniedPage (org.apache.wicket.markup.html.pages.AccessDeniedPage)4 Url (org.apache.wicket.request.Url)4 MockInnerClassPage (org.apache.wicket.util.tester.MockPageParameterPage.MockInnerClassPage)4 SuccessPage (org.apache.wicket.util.tester.apps_1.SuccessPage)4