Struts 2 s: select with values ​​from the resource bundle

We use s:select to display a list of strings from a resource set.

In action:

 //bank codes will be something [12,13,14] List<String> bankCodesList; //with setter and getter String selectedBankCode; 

In message resources, each bank will have a name:

 bank.code.12= ALFM Bank bank.code.13= RIHN Bank .... 

In JSP:

  <s:select name = "selectedBankCode" list = "bankCodesList" listKey = "toString()" listValue = "%{getText('bank.code.' + toString())}" /> 

Since the list of banks is List<String> , we used toString() to get the key and used toString() to get the value from the resource bundle.

I found that s:select has the status attribute the same as s:iterator , but I could not find it!

So, you think there are better ways ?!

+6
source share
1 answer

You don't need to call toString() in the listKey attribute at listKey so you can remove this attribute. And in listValue you can use the top keyword.

 <s:select name = "selectedBankCode" list = "bankCodesList" listValue = "%{getText('bank.code.' + top)}" /> 

The top keyword is mentioned here and here in the examples.

+7
source

All Articles