如果字段值无效,如何更改Struts2验证错误消息? [英] How to change the Struts2 validation error message in the case of an invalid field value?

查看:116
本文介绍了如果字段值无效,如何更改Struts2验证错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络表单上使用Struts2验证。如果字段被假定为整数或日期,则我收到的< s:fielderror> 消息是泛型无效字段值对于字段[fieldname]当然,我想为用户自定义此项。

I'm using Struts2 validation on a web form. In the case that a field is suppose to be an integer or Date, the <s:fielderror> message I receive is a generic Invalid field value for field "[fieldname]" Naturally, I want to customize this for the user.

以下是验证示例:

<field name="spouseDOB">
    <field-validator type="date">
        <message>"Spouse Date of Birth" is invalid.</message>
    </field-validator>
    <field-validator type="date">
        <param name="min">01/01/1900</param>
        <message>"Spouse Date of Birth" must be after 1900 AD.</message>
    </field-validator>
</field>

消息配偶出生日期无效。永远不会出现。输出是字段spouseDOB的通用无效字段值

The message "Spouse Date of Birth" is invalid. never appears, for any invalid date that I have tried. The output is the generic Invalid field value for field spouseDOB

spouseDOB 是动作类中的 java.util.Date 对象。它由JSP中的< s:textfield> 设置。

spouseDOB is a java.util.Date object in the action class. It is set by a <s:textfield> in the JSP.

推荐答案

ApplicationResources.properties 文件中,插入

invalid.fieldvalue.spouseDOB = "Spouse Date of Birth" is invalid.

如果您没有该文件,请查看这个

If you don't have that file, look at this.

这篇关于如果字段值无效,如何更改Struts2验证错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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