2
回答
struts2 <s:submit>国际化时提示警告
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

环境:apache-tomcat-6.0.18+struts-2.3.14

<s:submit key = "login.register.submit"/>

提交后,页面可以正常显示,但是在后台却打出了error:

2013-6-1 14:39:43 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Error setting expression 'login.register.submit' with value '[Ljava.lang.String;@121df2a'
ognl.OgnlException: source is null for getProperty(null, "register")
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:2310)
at ognl.ASTProperty.getValueBody(ASTProperty.java:114)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:212)
at ognl.SimpleNode.getValue(SimpleNode.java:258)
at ognl.ASTChain.setValueBody(ASTChain.java:222)
at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
at ognl.SimpleNode.setValue(SimpleNode.java:301)
at ognl.Ognl.setValue(Ognl.java:737)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:224)

求大神解答...

以上。

举报
wangbiglei
发帖于5年前 2回/908阅
共有2个答案 最后回答: 4年前

问题找到了,是<s:submit/>国际化的问题。

原先的代码是这样的:

<s:submitkey = "login.register.submit"/>

现在改成:

<s:submit value = "%{getText('login.register.submit')}"/>

or

<s:submit key = "submit"/>

就没有问题了。

是<s:submit/>标签国际化必须这样吗?有这样的规则在里面。

引用来自“wangbiglei”的答案

问题找到了,是<s:submit/>国际化的问题。

原先的代码是这样的:

<s:submitkey = "login.register.submit"/>

现在改成:

<s:submit value = "%{getText('login.register.submit')}"/>

or

<s:submit key = "submit"/>

就没有问题了。

是<s:submit/>标签国际化必须这样吗?有这样的规则在里面。

If atextfieldis passed the value attribute"ca", the framework will look for a property namedgetCa. Generally, this is not what we mean. What we mean to do is pass a literal String. In the expression language, literals are placed within quotes

Passing a literal value the right way
<s:textfieldkey="state.label"name="state"value="%{'ca'}"/>

Another approach would be to use the idiomvalue="'ca'", but, in this case, using the expression notation is recommended.

Boiled down, the tag attributes are evaluated using three rules.

  1. All String attribute types are parsed for the "%{ ... }" notation.
  2. All non-String attribute types are not parsed, but evaluated directly as an expression
  3. The exception to rule #2 is that if the non-String attribute uses the escape notion "%{}", the notation is ignored as redundant, and the content evaluated.

http://struts.apache.org/release/2.3.x/docs/tag-syntax.html

顶部