Versions Compared

Key

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

...

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;
	}

}

Overriding All Error Pages for RuntimeException

Sometimes it is desirable to override all of Wicket's error pages with a custom error page(s) when any RuntimeException occurs. Here is an example of how to do so.

Code Block

public final class MyRequestCycle extends WebRequestCycle {

	/**
	 * MyRequestCycle constructor
	 * 
	 * @param application the web application
	 * @param request the web request
	 * @param response the web response
	 */
	public WebRequestCycle(final WebApplication application, final WebRequest request, final Response response) {
		super(application, request, response);
	}
		
	/**
	 * {@inheritDoc}
	 */
	@Override
	protected final Page onRuntimeException(final RuntimeException e, final Page cause) {
		// obviously you can check the instanceof the exception and return the appropriate page if desired
		return new MyExceptionPage(e);
	}
}

Then in your WebApplication class :

Code Block

/**
 * {@inheritDoc}
 */
@Override
public final RequestCycle newRequestCycle(final Request request, final Response response) {
	return new MyRequestCycle (this, (WebRequest)request, (WebResponse)response);
}

How do I add/display errors?

...