Define own feedback messages in Wicket

前端 未结 4 2188
自闭症患者
自闭症患者 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:41

    @user1090145: I've used overloaded Component's error() method in Validator's class:

    private void error(IValidatable validatable, String errorKey) {
        ValidationError error = new ValidationError();
        error.addMessageKey(errorKey);
        validatable.error(error);
    }
    

    and invoked it in validate() by

    error(validatable, "your-form.field.text-id");
    

    Properties your-form.field.text-id must be defined in YourPage.properties

    Sources: Create custom validator in Wicket and Form validation messages

提交回复
热议问题