Struts2 i18NInterceptor不再使用ExecuteAndWaitInterceptor

时间:2012-10-02 01:06:27

标签: struts2

我正在使用struts2 tiles插件(v2.2.3),我遇到了使用I18nInterceptor和ExecuteAndWaitInterceptor的问题。基本上当我添加execAndWait拦截器(参见下面的xml)由于某种原因本地化不再有效时,当我尝试获取本地化文本(例如TextProviderSupport.hasKey)时,我得到一个NullPointerException(请参阅错误),我将其缩小为此代码LocalizedTextUtil ...

public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args) {
    ValueStack valueStack = ActionContext.getContext().getValueStack();
    return findText(aClass, aTextName, locale, defaultMessage, args, valueStack);

}

...我假设getValueStack()由于某种原因为空,但我无法弄清楚原因。有什么想法吗?

谢谢, 莱恩

<pre><code>    
    java.lang.NullPointerException
      at com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:359)
      at com.opensymphony.xwork2.TextProviderSupport.hasKey(TextProviderSupport.java:98)
      at com.opensymphony.xwork2.ActionSupport.hasKey(ActionSupport.java:96)
      at com.test.plus.PlusSupport.getCurrentLocale(PlusSupport.java:213)
      at com.test.plus.import.Test.action.TestAction.testMethod(TestAction.java:801)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
      at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
      at org.apache.struts2.interceptor.BackgroundProcess$1.run(BackgroundProcess.java:57)
      at java.lang.Thread.run(Unknown Source)
</code></pre>

Struts.xml

<action name="Test/m/testMethod" method="testMethod" class="com.test.plus.import.Test.action.TestAction">
    <result type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
    <result name="success" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
    <result name="input" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
    <result name="error" type="tiles">/WEB-INF/jsp/import/Test/testMethod.jsp</result>
    <result name="wait" type="tiles">/WEB-INF/jsp/import/execAndWait.jsp</result>
    <interceptor-ref name="plusStack"/>
    <interceptor-ref name="defaultStack"/>
    <interceptor-ref name="execAndWait">
      <param name="excludeMethods">input,back,cancel</param>
    </interceptor-ref>
</action>

1 个答案:

答案 0 :(得分:1)

来自http://struts.apache.org/2.x/docs/execute-and-wait-interceptor.html

  

重要提示:由于操作将在单独的线程中运行,因此您无法使用ActionContext,因为它是ThreadLocal。这意味着如果您需要访问例如会话数据,则需要实现SessionAware而不是调用ActionContext.getSession()。