This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Learn Java with Math: Using Fun Projects and Games and have Ron Dai on-line!
See this thread for details.
Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

options sorting on property?

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to sort the list in the following select on the budgetName property, can I do that within struts?
If not and I sort the list of javabeans in the collection before going onto the page, is it guaranteed that the beans would be accessed in order?

Any suggestions would be appreciated
thanks
B
[smilies disabled by moderator]
[ October 24, 2003: Message edited by: Junilu Lacar ]
 
Marshal
Posts: 14453
240
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use a List (e.g. ArrayList) and the order will be retained.
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We build most of our collections stuff in TreeList and everything comes out in order. I've never had any issues.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If budgetlist is a List, call the Collections.sort() method.
You have two choices:
1) Implement the Comparable interface for the class of objects stored in your collection (Budget class?)
or
2) Use the overloaded sort() method which accepts a Comparator
For approach 1), add this line to your code which retrieves the budgetlist:
Collections.sort(budgetlist);
-Mark
 
Busty Sinclair
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought there might be some struts way I could include which property to sort on. Mark, your 2nd approach seems to be what I need, I'll write a comparator class. Thanks for the replies all. B
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!