I have included a quick example of doing this by using a list of hashmaps. The hashmap holds the text that may appear in the pulldown.

list = new ArrayList();
for (Iterator i = myObjects.iterator(); i.hasNext();) {
Map map=new HashMap();
map.put("firstName","Joe");
map.put("lastName","Smith");
map.put("fullName","Joe Smith");
map.put("someOtherField","blue"); list.add(map);
}


to sort the list we use can do this:

Collections.sort(list, new BeanComparator("lastName"));

(this uses the BeanComparator from here http://jakarta.apache.org/commons/beanutils.html)

This will sort ascending by default, so to get decending I can do this afterwards...

Collections.reverse(list);


Dinh Nguyen wrote:


Hi Tim,

In this case, I have to display the sorted list (ascending and descending) for names, etc. How do I do this? How can I pull the objects from the back-end. I am thinking to use collections.sort(list, comparator)as you mentioned or use sortedset and using arraylist (or hashset) to hold objects.
For searching, I am thinking to use hashtable, but have no idea what's the next step. I use the EJB as back-end and has not implemented it yet.


If you can give me feedback on this or give me some kinds of ideas, then it'll be great. Thanks for your help.
Dinh Nguyen


--- In [EMAIL PROTECTED], "Chen, Gin" <[EMAIL PROTECTED]> wrote:


I'm not sure I understand this question but wouldn't you just

implement some


comparators?
Then based on the sort option selected you can call something like:
Collections.sort(list, comparator)?
As for the search just have a java module to search thru the


collection.


I'm not quite sure how what this question really has to do with

Struts.


Unless you use something like the displaytags to display a

sortable list for


the names.
-Tim

-----Original Message-----
From: Ruth, Brice [mailto:[EMAIL PROTECTED] Sent: Thursday, October 23, 2003 1:26 PM
To: Struts Users Mailing List
Subject: sorting and searching in Struts/tiles



[Forwarded from Dinh Nguyen, his emails aren't reaching the list]


Dinh Nguyen wrote:

Hi,

I am wondering how do you do the sorting and searching in struts.
Let say, when a person views a list of collections (for example,


the


list consists of 5 people, each person has first name, last name,
age), there is a drop-down menu on the bottom of the table/page


says


that:
1) Sort has two options: a) Ascending b) Descending
2) Search has three options a) Last Name b) First Name c) Age

Since data is not stored in database yet.
so in this case how can I do it using Struts?

Thanks for your help.

DN


-------------------------------------------------------------------


--


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-------------------------------------------------------------------


--


To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]






--
Jason Lea




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to