Another alternative is LinkedHashMap, available in JDK 1.4. It can maintain
either insertion-order or access-order.

Quoting "Popova, Marina" <[EMAIL PROTECTED]>:

> you could also try using TreeMap - it is ordered. You might also consider
> writing your own comparator for keys if you don't like the default one 
> 
> Marina
> 
> -----Original Message-----
> From: Martin Cooper [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, November 04, 2003 7:10 PM
> To: Tag Libraries Users List
> Subject: Re: How to maintain the selection items in the Select using the
> jakarta.apache.org input tag library
> 
> 
> On Tue, 4 Nov 2003, Kimberly Clary wrote:
> 
> >
> >
> >
> >
> > I want to have the items in my Select list showing in a certain order.
> > I've looked over both the html and jsp examples that were provided when I
> > downloaded the tag lib but they only contain the basics.
> >
> > I enter the following in my jsp -
> >
> >           <td nowrap>
> >             <label for="bac">BAC<br>Code:<br>(none or all<br>returns
> > all)</label><br>
> >           </td>
> >           <td>
> >             <%
> >             java.util.HashMap b = new java.util.HashMap();
> >             b.put("id", "bac");
> >             b.put("multiple", null);
> >             b.put("size", "6");
> >
> >             java.util.Hashtable bo = new java.util.Hashtable();
> >             bo.put("CSP", "1");
> >             bo.put("FAP", "2");
> >             bo.put("FRU", "3");
> >             bo.put("OPT", "4");
> >             bo.put("PPN", "5");
> >             bo.put("Paper", "6");
> >             %>
> >             <input:select name="bac" attributes="<%= b %>" options="<%=
> > bo%>" />
> >           </td>
> >
> > but the data doesn't display in this order.
> > It's showing up in the order of     -----
> >
> >             FAP
> >             OPT
> >             PPN
> >             Paper
> >             CSP
> >             FRU
> >
> > I think the code should be using the getKey method for building this
> > selection list if we want to maintain the order.
> 
> HashMaps and Hashtables are unordered collections. The order in which you
> add elements to them does not make any difference at all. If you need to
> preserve that order, you may want to take a look at the SequencedHashMap
> class in the Jakarta Commons Collections package.
> 
> --
> Martin Cooper
> 
> 
> > Can someone help me?
> > Thanks - Kim
> >
> > ---------------------------------------------------------------
> > Kim Clary
> > Global AMS Delivery
> > Internet Design and Development
> > Tie: 444-2396  Ph:919-254-2396
> >
> > "Life gets boring if you stay within the limits"

-- 
Kris Schneider <mailto:[EMAIL PROTECTED]>
D.O.Tech       <http://www.dotech.com/>

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

Reply via email to