2011-11-14 69 views
1

我的Web程序配置是Struts2和Tomcat 6.0。Struts2 ActionSupport getTexts()不工作

和我的項目是支持i18n的(國際〜)

我用類擴展com.opensymphony.xwork2.ActionSupport

getText(String)方法有效,但getTexts()不起作用。

public class MyAction extends ActionSupport { 
    public void textString() { 
     // print "en" works 
     String strTemp1 = getText("CURRENT.LOCALE"); 
     System.out.println(strTemp1); 

     // This doesn't; bundle is null. 
     ResourceBundle bundle = getTexts(); 
     System.out.println(bundle); 
    } 
} 

globalMessage_en.properties

CURRNET.LOCALE = en 
+0

你可以提供詳細信息,如何訪問that.generally getTexts()獲取與實現類相關的資源包(通常是一個操作)。 –

+0

屬性文件中的'CURRENT.LOCALE'拼寫錯誤是否爲拼寫錯誤?另外,你如何在S2配置中聲明全局消息資源? –

+0

Thx確實有幫助 – afraxas

回答

1

如預期這實際工作。從docs of TextProvider.getTexts()):

獲取與實現類關聯的資源包(通常是一個操作)。

由於您只有全局消息資源,它將返回null。如果您的操作需要特定的消息資源(例如MyAction.properties與您的操作位於同一目錄中),則會返回相應的ResourceBundlePropertyResourceBundle)。