Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Excerpt
hiddentrue
  • HTTP, Non-HTTP, and Displaying


How do I add custom error pages?

...

Code Block
// show internal error page rather than default developer page
getExceptionSettings().setUnexpectedExceptionDisplay(IExceptionSettingsExceptionSettings.SHOW_INTERNAL_ERROR_PAGE);

...

This is assuming that you have mapped "/404" in your WebApplication:

Code Block
	mount(new HybridUrlCodingStrategymountPage("/404", PageNotFound.class));

In your error WebPage:

Code Block
public class PageNotFound extends WebPage {

	private static final long serialVersionUID = 1L;

	public PageNotFound() {
		// Add any necessary components
	}

	@Override
	protected void configureResponse() {
		super.configureResponse();
		getWebRequestCycle().getWebResponse().getHttpServletResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
	}

	@Override
	public boolean isVersioned() {
		return false;
	}

	@Override
	public boolean isErrorPage() {
		return true;
	}

}

...

Code Block
// also see AbortWithWebErrorCodeException and AbortWithHttpStatusException
throw new AbortWithHttpStatusException(404, true);

For wicket 6 and beyond:

Code Block

throw new AbortWithHttpErrorCodeException(404, "Some message");

Overriding All Error Pages for RuntimeException

...