在 Wicket 中定义自己的反馈消息 [英] Define own feedback messages in Wicket

查看:24
本文介绍了在 Wicket 中定义自己的反馈消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 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?

推荐答案

您可以使用 error()warn() 显示自己的错误消息信息().如果您想显示依赖于验证器或所需标志的错误,您可以定义一个与包含字段 -> 消息映射的类同名的属性文件.例如:

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...

所有必填字段

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

myform 表单中的字段 name 需要时.

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

password.Required=You have to provide a password

任何需要名称password的字段.

phonenumber.Required=A telephone number is obligatory.

任何需要名称为 phonenumber 的字段.

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):

  • 页面类
  • 组件类
  • 您的应用程序类
  • Wickets 应用类

希望有帮助

这篇关于在 Wicket 中定义自己的反馈消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆