Struts 2 s:使用资源包中的值进行选择 [英] Struts 2 s:select with values from resource bundle
问题描述
我们正在使用s:select
显示资源束中的字符串列表.
We are using the s:select
to show a list of string from resource bundle.
在行动中:
//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
....
在JSP中:
<s:select name = "selectedBankCode"
list = "bankCodesList"
listKey = "toString()"
listValue = "%{getText('bank.code.' + toString())}" />
由于银行清单为List<String>
,因此我们使用toString()
获取密钥,并使用toString()
从资源束中获取价值.
As the bank list is List<String>
we used toString()
to get the key and used toString()
to get value from resource bundle.
除了找到s:select
具有与s:iterator
相同的status
属性外,我找不到任何东西!
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?!
推荐答案
您根本不需要在listKey
属性中调用toString()
,因此可以删除此属性.在listValue
中,您可以使用top
关键字.
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)}" />
这篇关于Struts 2 s:使用资源包中的值进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!