您的位置:程序门 -> java -> 框架、开源



100分求助, 关于struts2的properties文件中,使用ognl表达式问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


100分求助, 关于struts2的properties文件中,使用ognl表达式问题
发表于:2008-01-15 23:20:00 楼主
我尝试在globalmessages.properties里面,使用ognl表达式,如下
startdate=xxxxx
enddate=xxxxx
xwork.default.invalid.fieldvalue=${gettext(filedname)}   yyyyy

执行时出现错误
java.lang.illegalargumentexception:   can't   parse   argument   number   gettext(filedname)

查看文档
http://struts.apache.org/2.x/docs/localizing-output.html
里面有例子
requiredstring   =   $\{gettext(fieldname)}   is   required.
但我改成$\gettext(filedname)}也报错

搜索了一晚上,没有找到解决方案,但找到一个同样问题的帖子
http://readlist.com/lists/struts.apache.org/user/7/35380.html
也是没有解决


发表于:2008-01-16 08:54:001楼 得分:0
xwork.default.invalid.fieldvalue=${gettext(filedname)}       yyyyy       类型不匹配,或获得了null值,或不能string转为int,加try/catch看看
发表于:2008-01-16 13:18:432楼 得分:0
关注
发表于:2008-01-20 16:28:363楼 得分:0
楼主是不是在使用struts2的内置类型转换想输出错误信息?

xwork.default.invalid.fieldvalue=${gettext(filedname)}       yyyyy  
在资源文件里不能使用${gettext(filedname)}
应该使用占位符
xwork.default.invalid.fieldvalue=${0}   yyyyy
这样会把出错的属性名传递过${0}   来显示

还有一种方式输出内置类型转换错误的
为你的action建立一个局部的资源文件actionname.properties
然后在里面添加
invalid.fieldvalue.属性名=错误提示信息
actionname   是指定你为哪个action配置的局部资源文件
属性名写actionname指定的action中的属性  


快速检索

最新资讯
热门点击