如何动态地从 *.properties 文件填充 h:selectItems
如果我有这样的代码:
<rich:select enableManualInput="true" defaultLabel="Select time spent">
<f:selectItems value="" />
</rich:select>
和一个属性文件,例如:
key1=val1
key2=val2
key3=val3
key4=val4
问题是如何从属性文件中获取所有值并从中创建一个 ArrayList
以便我可以使用它们在下拉列表中?
If I have this peace of code:
<rich:select enableManualInput="true" defaultLabel="Select time spent">
<f:selectItems value="" />
</rich:select>
and a properties file like:
key1=val1
key2=val2
key3=val3
key4=val4
The question is how to take all the values from the properties file and make a ArrayList<SelectItems>
from them for example so I can use them in the drop-down list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您可以更改属性文件的布局,我建议像
属性教程一样存储它: http://download.oracle.com/javase/tutorial/essential/environment/properties.html
API:http://download.oracle.com/javase/6/docs /api/java/util/Properties.html。
不幸的是,属性由 Hashtable
If you can change the layout of your properties file i would suggest storing it like
Properties Tutorial: http://download.oracle.com/javase/tutorial/essential/environment/properties.html
Api: http://download.oracle.com/javase/6/docs/api/java/util/Properties.html.
Unfortunately Properties is backed by a Hashtable<Object,Object>. But unless you mess with it, the casts should be safe.