Struts2 文本域中数值格化的疑问

在Struts2.0.11.1版本,相应的指南中
[url]http://struts.apache.org/2.0.11.1/docs/formatting-dates-and-numbers.html[/url]
Localizing form data with getText
Localizing form data with getText
[b]Placing a textfield in a form like this[/b]

<s:textfield key="orderItem.price" />

[quote]to input a number, one might have noticed that the number is always shown in the Java default number format. Not only that this is not "nice", if you are in a non-en locale, it will also cause trouble when submitting the form since type conversion is locale aware. The solution is to again use the message formats as defined above, by using the getText Method of ActionSupport:[/quote]

<s:textfield key="orderItem.price" value="%{getText('format.number',{'orderItem.price'})}" />

[quote]This maps to the method signature getText( String key, Object[] params ) in ActionSupport.[/quote]

我在页面中如下使用:
<s:textfield key="orderOprRecord.jsFee" value="%{getText('format.number',{'orderOprRecord.jsFee'})}" size="8"/>


发现调用的是:
getText( String key, List args) in ActionSupport.
而非
getText( String key, Object[] params ) in ActionSupport
当然,这二个方法其实都调用同一个函:
LocalizedTextUtil.findText(clazz, key, getLocale(), defaultValue, argsArray);

详见:xwork-2.04,TextProviderSupport.java
最终发现,argsArrays为:['orderOprRecord.jsFee']
最后在LocalizedTextUtil.java,第590行
if (message != null) {
MessageFormat mf = buildMessageFormat(TextParseUtil.translateVariables(message, valueStack), locale);

String msg = mf.format(args);
result = new GetDefaultMessageReturnArg(msg, found);
}

String msg = mf.format(args);
这时,agrs内的值仍是:['orderOprRecord.jsFee']
自始自终没有经过处理,即没有在ValueStack中取出对应的值.
所以msg最后的值为空.

下面的难道是:struts2的手册的作者的笔误吗?
<s:textfield key="orderItem.price" value="%{getText('format.number',{'orderItem.price'})}" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值