Alireza Fattahi
Alireza Fattahi

Reputation: 45593

Format text with more than one parameter in struts 2

Is it possible to directly format a text which has many place holders in message resource in struts 2?

As an example, consider below keys, which should produce 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

In the action I want to invoke something like this (which is not valid!!):

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

I know that I can first get the filename and then use java Formatter.

On the other hand I find examples which format the messages directly. As you know this is valid

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

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

Can I use the above solution (shortcut) to format the filename

Upvotes: 1

Views: 1384

Answers (1)

Aleksandr M
Aleksandr M

Reputation: 24406

You need to pass your parameters as array or as list, because getText method is overloaded like that:

getText(String key, String[] args)

and

getText(String aTextName, List<?> args)

For example:

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

Upvotes: 2

Related Questions