Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define own feedback messages in Wicket

Tags:

wicket

How do I define my own feedback messages in Wicket? For example: if I give an incorrect username, I want to get an error message like "The user name in incorrect, try to login again." instead of using the default error message.

What would an example be like?

like image 950
Robo Avatar asked Apr 21 '11 04:04

Robo


1 Answers

You can display your own error messages using error() and warn() and info(). If you want to show errors dependent on validators or the required flag you can define a properties file with the same name as the class which contains a mapping of field -> message. For example:

Index.java

Form form = new Form("myform");
form.add(new TextField("name").setRequired(true));
form.add(new PasswordTextField("password").setRequired(true));
form.add(new TextField("phonenumber").setRequired(true));

Index.properties

Required=Provide a ${label} or else...

All required fields

myform.name.Required=You have to provide a name

The field name in the form myform when it is required.

password.Required=You have to provide a password

Any field with the name password when it is required.

phonenumber.Required=A telephone number is obligatory.

Any field with the name phonenumber when it is required.

This shows a variety of ways of setting a feedback message for specific components.

You can also put the properties files next to the following component level (in order of importance, top highest):

  • Page Class
  • Component Class
  • Your Application Class
  • Wickets Application Class

Hope that helps

like image 113
mark-cs Avatar answered Sep 26 '22 03:09

mark-cs