Struts 2 s:select with values from resource bundle

丶灬走出姿态 提交于 2020-01-02 03:26:29

问题


We are using the s:select to show a list of string from resource bundle.

In the Action:

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

In the message resources each bank will have a name:

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

....

In the JSP:

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

As the bank list is List<String> we used toString() to get the key and used toString() to get value from resource bundle.

I excepted to find the s:select has a status attribute same as s:iterator but I could not find any!

So you think there are better ways?!


回答1:


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

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

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



来源:https://stackoverflow.com/questions/23494891/struts-2-sselect-with-values-from-resource-bundle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!