theonedev/onedev · error · WicketRuntimeException
No Page found for component
Error message
No Page found for component
What it means
Component.getPage() calls findPage() and throws this WicketRuntimeException if the component is not attached to a Page. Many Wicket APIs (URL generation, session access, request targets) require a page, so calling them on a detached or unattached component surfaces this error.
Source
Thrown at server-core/src/main/java/org/apache/wicket/Component.java:1770
/**
* Gets the page holding this component.
*
* @return The page holding this component
* @throws WicketRuntimeException
* Thrown if component is not yet attached to a Page.
* @see #findPage()
*/
@Override
public final Page getPage()
{
// Search for nearest Page
final Page page = findPage();
// If no Page was found
if (page == null)
{
// Give up with a nice exception
throw new WicketRuntimeException("No Page found for component " + this);
}
return page;
}
/**
* Gets the path to this component relative to its containing page, i.e. without leading page
* id.
*
* @return The path to this component relative to the page it is in
*/
@Override
public final String getPageRelativePath()
{
return Strings.afterFirstPathComponent(getPath(), PATH_SEPARATOR);
}
/**View on GitHub (pinned to d44925c47c)
Solutions
- Defer page/request-dependent logic to onInitialize(), onBeforeRender(), or onConfigure() instead of the constructor
- Ensure the component is added to a Page before calling getPage()-dependent APIs
- In constructors, use the constructor parameters (e.g. IModel) instead of getRequest()
- In tests, start the page first so the component hierarchy is attached
Example fix
// before
public MyPanel(String id) {
super(id);
setResponsePage(Home.class); // no page yet
}
// after
public MyPanel(String id) {
super(id);
add(new Link<Void>("go") {
@Override
public void onClick() {
setResponsePage(Home.class);
}
});
} Defensive patterns
Strategy: type-guard
Validate before calling
if (component.findPage() == null) {
// defer page-dependent logic until attached
return;
} Type guard
boolean isAttachedToPage(Component c) {
return c.findPage() != null;
} Try / catch
try {
component.getPage().getUrl();
} catch (WicketRuntimeException e) {
if (e.getMessage().startsWith("No Page found for component")) {
// component is not in a page hierarchy yet
}
} Prevention
- Never call getPage()/getRequest() in component constructors; use onInitialize/onBeforeRender
- Pass IModel data through constructors instead of request lookups
- Call page-dependent APIs only from link onClick(), onSubmit(), or render-phase hooks
When it happens
Trigger: Calling getPage(), getRequest(), getResponse(), urlFor(), setResponsePage, etc. on a component that has not been added to a page, or after it was removed; also during constructor code that runs before the component is added to its parent.
Common situations: Accessing getRequest()/getPage() inside a component's constructor (component not yet parented); calling page-dependent APIs on components removed from the hierarchy; tests that forget startPage/createRequestCycle.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- has not been properly added. Something in the hierarchy of
- Could not find Form parent for {this}
- Page classes should extend from BasePage.
- Base resource mapper should be used
- Invalid date range, expecting "yyyy-MM-dd to yyyy-MM-dd"
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/63ca83104dba76af.
Report an issue: GitHub.