Struts 2 s:使用资源包中的值进行选择 [英] Struts 2 s:select with values from resource bundle

查看:97
本文介绍了Struts 2 s:使用资源包中的值进行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用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)}" />

提到top关键字>此处此处.

这篇关于Struts 2 s:使用资源包中的值进行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆