2009年9月15日 星期二

[Struts2]TextProvider

在後端使用resource bundle
Struts的話我是用messageResources.getMessage(locale, key)來處理
Struts2的話之前還沒用到過
便查了一下API
找到了TextProvider
以下節錄一段敘述
public interface TextProvider

Provides access to ResourceBundles and their underlying text messages. Implementing classes can delegate TextProviderSupport. Messages will be searched in multiple resource bundles, startinag with the one associated with this particular class (action in most cases), continuing to try the message bundle associated with each superclass as well. It will stop once a bundle is found that contains the given text. This gives a cascading style that allow global texts to be defined for an application base class.

而且ActionSupport已經Implemented了

所以在Struts2里的用法更簡單
在有extends ActionSupport的class下
super.getText("keyYouType")
這樣就可以取出對應的值了!

沒有留言:

張貼留言