Versions Compared

Key

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

...

A "two-phase init" is a pattern that deals with this and other use cases. The big downside to that pattern is that you have to transfer all your constructor arguments into fields so they can be accessed by the second phase' init method, and for a framework concerned with size of the objects this does not mesh very well. It also adds a lot more code you have to write. so as far as making this change in Wicket we won't do that. Moreover, it is simple enough to add a private init() into your basepage and forward both constructors to it.

How do I add custom error pages

...

?

see Error Pages

In your application class that extends WebApplication, set the following in the init() method:

...


getApplicationSettings().setPageExpiredErrorPage(MyExpiredPage.class);
getApplicationSettings().setAccessDeniedPage(MyAccessDeniedPage.class);
getApplicationSettings().setInternalErrorPage(MyInternalErrorPage.class);

There are also some other neat settings you should check out in getApplicationSettings(), getDebugSettings(), getExceptionSettings(), getMarkupSettings(), getPageSettings(), getRequestCycleSettings(), getSecuritySettings and getSessionSettings(). See the javadoc for more information.

If calling setInternalErrorPage, make sure to also call:

Code Block

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

You can also add customized error per page. In your WebPage class:

Code Block

getRequestCycle().onRuntimeException(new MyErrorPage(), theException);

How do I add/display errors?

Normally all that is needed to display errors in a page is to call the "error" method in the WebPage:

Code Block

error("Message to the user indicating that an error occurred");

// alternative to get the message from a .properties file: error.login.user.invalid=${username} is not a valid user
error(new StringResourceModel("error.login.user.invalid", this, myUserModelThatHasAUsernameProperty).getString());

If an error occurred where the user needs to be directed to a different page we need to set the error on the session:

Code Block

getSession().error(message);
throw new RestartResponseException(MyErrorPage.class, optionalPageParameters);
// use RestartResponseAtInterceptPageException(MyErrorPage.class);
// instead to interrupt current request processing and immediately redirect to an intercept page

// it may be tempting to do the following, but it should not be done:
// error(message);
// setResponsePage(MyErrorPage.class);

To display an error (or any message for that matter: info/warning) in an HTML page use a FeedbackPanel:

Code Block

<!-- In the HTML page -->
<div wicket:id="feedback">[Feedback Panel]</div>

// In WebPage
add(new FeedbackPanel("feedback"));

// TODO : add example that adds error messages to individual form components of the page

I get 'Internal error cloning object' errors

This is a debug feature to help find potential problems when the application runs clustered. It checks the component graphs to make sure everything is serializable (which is required for clustering).

If clustering support is not needed, these checks can be disabled by doing getDebugSettings().setSerializeSessionAttributes(false); in the application.init()

Also, if the configuration parameter in the web.xml is set to DEPLOYMENT, these checks are disabled.

Answer provided courtesy Igor Vaynberg

How can I have images/files uploaded to and downloaded from my wicket app?

...