Define own feedback messages in Wicket

前端 未结 4 2190
自闭症患者
自闭症患者 2021-02-13 12:25

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

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 12:53

    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

提交回复
热议问题