You will need to use a different data structure. One idea is to make
use of java.util.SortedMap
(http://java.sun.com/j2se/1.4.1/docs/api/java/util/SortedMap.html),
which is very similar to a struct except that the keys are kept in
order based on a Comparator passed to the constructor.
-Matt
On Thursday, July 31, 2003, at 10:55 AM, Suyer, Ed [PRD Non-J&J] wrote:
> Hi folks,
>
> Does anyone know of a way to preserve the order of keys in a structure
> so
> that it matches the order in which it was created?
>
> i.e.
>
> I created a structure that looks like so:
>
> instance structNew();
>
> instance["id"] = structNew();
> instance["id"].heading = "Id";
> instance["id"].size = 50;
>
> instance["manufacturer_name"] = structNew();
> instance["manufacturer_name"].heading = "MFG";
> instance["manufacturer_name"].size = 200;
>
> instance["name"] = structNew();
> instance["name"].heading = "Name";
> instance["name"].size = 100;
>
> instance["parttype_name"] = structNew();
> instance["parttype_name"].heading = "Part Type";
> instance["parttype_name"].size = 100;
>
> instance["status_name"] = structNew();
> instance["status_name"].heading = "Status";
> instance["status_name"].size = 100;
>
> When I cfloop through it ( i.e. for ( field in instance ) {} ), I would
> expect it to find the "id" field first, then "manufacturer_name", and
> so on
> and so fourth in the order in which the structure was created.
> Instead it
> loops through in this order:
> name,id,parttype_name,manufacturer_name,status_name
>
> I figured I'd try to trick it by doing a structKeyList() then cflooping
> through that, but it returns the same thing:
> name,id,parttype_name,manufacturer_name,status_name
>
> Does anyone know of a way to cfloop through this structure in the
> order in
> which it was created:
> id,manufacturer_name,name,parttype_name,status_name ?
>
> TIA!
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Get the mailserver that powers this list at
http://www.coolfusion.com
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4