`
- 浏览:
145723 次
- 性别:
- 来自:
北京
-
struts2 xml 验证出现 Invalid field value for field 的解决方法(转)
缺省情况下, 所有的装换错误使用通用的i18n信息 xwork.default.invalid.fieldvalue , 你可以在你的全局il8n资源包中替换他(缺省文本是"Invalid field value for field xxx", 这里xxx是字段名称).
局部修改:
无论如何, 有时你会希望能够在每个字段上替换这一信息. 你可以在action相关的资源文件(Action.properties)中添加一个i18n信息: invalid.fieldvalue.xxx, 这里xxx是字段名称.
需要知道的是, 这些错误不会直接报告出来. 他们被添加到ActionContext.conversionErrors中. 有几种方法可以访问该map从而可以报告这些错误.
示例:
<form action="add" method="post">
<s:fielderror></s:fielderror>
<input type="text" name="box">
<input type="text" name="width">
<s:submit value="添加"></s:submit>
</form>
如果age输入为不为数字时会提示
? Invalid field value for field "width".
其中Invalid field value for field "width" 信息是struts2通过内置的类型转换器进行类型转换时,如果不能成功转换, struts2框架自动生成一条错误信息,并将该错误信息放到addFieldError里面,这种默认的输出信息格式是在 xwork-2.1.2.jar中定义com/opensymphony/xwork2/xwork-messages.properties文件中有一条xwork.default.invalid.fieldvalue=Invalid field value for field "{0}".这是一种全局的错误提示方式,整个系统中只要是字段类型转换错误都会这样提示,我们也可以改变这种输出格式,只要在全局的国际资源文件中重写xwork.default.invalid.fieldvalue就可以了.实现方式:在struts.xml中加入<constant name="struts.custom.i18n.resources" value="messageResource"></constant>或者也可以在struts.properties中加入struts.custom.i18n.resources=messageResource
指定国际化资源文件名为messageResource. Properties
新建messageResource. Properties资源文件并添加数据xwork.default.invalid.fieldvalue={0} failure
修改之后字段类型转换错误提示为 : {0} failure所有的类型转换失败后,struts2会将基本类型设置为0,对象类型设置为null,这里的age的类型为Integer,当类型转换失败age值为null,如果age的类型为int,那么转换失败后值为0
这种提示信息不够友好,也可以定义局布的提示信息,为每一个Action新建一个properties文件,文件名为XXX.properties(Action名.properties)
实现方式:新建RegistAction.properties并添加
invalid.fieldvalue.width=width error
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
struts 初步认识Struts2并部署验证 ...struts8 全局性的验证xwork.default.invalid.fieldvalue={0} error struts9 进行局部性的验证,使用struts2标签库对register.jsp进行改进 strrts10 第七讲struts2中的案例
myelicpse 出现Invalid location of tag的问题解决方法
struts2-scan 检测struts2漏洞,认证检测struts2漏洞
linux ls find 时大于2G文件时出现Value too large for defined data type 系统本身支持大于2G文件但查询有问题的解决办法
演示了 将SeekBar的progress指定为一张.9.png后,出现那个问题,以及解决方案。有一种.9图片,并不会出现那种情况。只需将里面的.png的图片引用,替换为.9.png即可。
强烈推荐,arcgis卸载出现,install.log文件复制到bin目录,找到卸载工具unwise32.exe
The value for key CFBundleShortVersionString [1.2] in the Info.plist file must contain a higher version than that of the previously approved version [1.15] 明明1.2的版本号要大于1.15,怎么还会出现错误...
打开lisense manager的安装目录,点uninstall,选择下载的install。log,祝各位好运。当然也可以选择window install cleaner up移除。
Altium Designer 19 原理图复制出现InvalidParameter at AdvSch.dll, Base Addre... 报错的解决办法
两步,帮助大家很容易实现卸载... (1)下载压缩包并解压得到install.log文件 (2)找到License的默认安转路径,找到卸载工具unwise32.exe,双击打开,选择(1)步下载的install.log文件,并点击next,即可实现完全卸载
唯一解决 Protel 99 SE 'Format '%x' invalid or incompatible with argument' 的方法 4核的电脑
struts2 常用Result类型(type)的用法 Invalid result location value/parameter错误的解决办法
NULL 博文链接:https://wilian.iteye.com/blog/1992365
TypeError: ‘required’ is an invalid argument for positionals 的解决方法 当我在使用argparse模块时,遇到了如下错误: import argparse parser = argparse.ArgumentParser(description = 'debug_example') ...
2.Installation of Struts 3.The First Try: Simple JSP 4.Second Try: Struts For Internationalisation 5.Struts for Forms 6.Struts: Introducing the ActionForm 7.A better way to seperate Book ...
解决出现Incorrect integer value: ” for column ‘id’ at row 1的问题 前言: 今天在学习Python的过程中操作数据库,遇到了一个问题,执行sql语句插入数据的时候报错Incorrect integer value: ” for column ‘id...
NULL 博文链接:https://universes.iteye.com/blog/854485
format ' x' invalid or incompatible with argument 解决办法
本人现在用的,一个比较好用的java反编译工具,需要的可以下。
主要介绍了引入mybatis-plus报 Invalid bound statement错误问题的解决方法,需要的朋友可以参考下