在 Wicket 中定义自己的反馈消息

编程入门 行业动态 更新时间:2024-10-24 08:32:16
本文介绍了在 Wicket 中定义自己的反馈消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

如何在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 03:12:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自己的   定义   反馈   消息   Wicket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!