2013-10-13 26 views
1

是否可以直接格式化struts 2中消息資源中擁有多個佔位符的文本?使用struts 2中的多個參數設置文本格式

舉個例子,考慮下面的鍵,它應該產生Transfer2000USDFromBobToMike

#resources.properties 
filename=Transfer{0}From{1}To{2} 

#resources_fa_IR.properties (consider this is correct translation in Persian!) 
filename={انتقال{0} از {1} به {2 

在我想要調用這樣的事情(這是無效的!)的作用:

getText("filename", amount,sourceAccount,destincationAccount); 

我知道我可以先獲得filename,然後使用java Formatter

另一方面,我找到直接格式化消息的例子。如你所知,這是有效的

message properties 
format.money = {0,number,\u00A4##0.00} 

jsp 
<s:text name="%{getText('format.money',{amount})}" /> 

我可以使用上述溶液(快捷方式)格式化filename

回答

2

你需要通過你的參數數組或列表,因爲getText方法重載這樣的:

getText(String key, String[] args) 

getText(String aTextName, List<?> args) 

例如:

getText("filename", new String[] { amount, sourceAccount, destincationAccount });