按字段对 java beans 集合进行排序
我有一个填充 JSF DataTable 的 java bean 集合,我正在尝试实现列排序。
我想根据所选字段对数组/集合进行排序。 我过去曾使用 Reflection 来实现此目的,但想找到一种更简洁的方法,使用 Commons BeanUtils 和/或 Collections,但似乎找不到任何示例。
谢谢 斯科蒂亚布
I have an collection of java beans that populate a JSF DataTable I'm trying to implement column sorting.
I'd like to sort the array/collection depending on the field selected. I have using Reflection in the past for this, but wanted to find a neater way of doing it, using Commons BeanUtils and/or Collections but can't seem to find any examples.
Thanks
Scottyab
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,经过一番尝试后,这就是我想到的,它似乎有效,
现在只需要查看排序顺序:)
Actually after a bit of playing around here's what i come up with and it seems to work
Just need to look at the sort order now :)
与您的具体问题没有立即相关,但请查看GlazedLists - 它使得在GUI上实现这些东西非常容易。
not immediately relevant to your specific question, but look at GlazedLists -- it makes implementing this stuff for GUI's really easy.