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

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

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

引用
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:


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

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


我在页面中如下使用:
<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'})}" />

你可能感兴趣的:(java,apache,html,struts)