4

我有一個java bean的集合,它填充一個JSF DataTable我試圖實現列排序。javabean按字段排序

我想根據所選字段對數組/集合進行排序。我過去爲此使用了Reflection,但是想用Commons BeanUtils和/或Collections來找到一個更好的方法,但似乎找不到任何示例。

感謝 Scottyab

回答

4

後其實有點打在這裏就是我想出和它似乎工作

String sortColumn = (String)getRequestParam("sort_id");  
List<Quote> quotes = (List<Quote>)getSessionScope().get(SESS_SEARCH_RESULTS);   
Comparator fieldCompare = new org.apache.commons.beanutils.BeanComparator(sortColumn); 
Collections.sort(quotes, fieldCompare); 

只需要看看現在的排序順序:)

0

與您的具體問題並不直接相關,但請看GlazedLists - 它使得爲GUI實現這些東西非常容易。