Re: The new map syntax
"Nikhil G. Daddikar" <[email protected]> Fri, 18 Nov 2005 17:24:25 +0530
| Newsgroups | gmane.comp.java.webmacro.user |
|---|---|
| Organization | Celoxis Technologies Pvt. Ltd. |
| Message-ID | <[email protected]> |
Thanks for your detailed response. I think the spirit of webmacro has been to be web-designer friendly. (That is why probably there is no while or break.) I don't think when web designers specify the new map syntax, they are expecting that the backend will sort it according to the keys or that the map is in a random order. It is telling them thet when you specify #set $l = [a, b, c], you may get the list in a random order. I think it is ok for a designer to call a function if he/she wants to sort it by key or value rather than messing up the order. -ngd Marc Palmer wrote: >-----Original Message----- >From: "Nikhil G. Daddikar" <[email protected]> >To: [email protected] >Date: Fri, 18 Nov 2005 10:52:24 +0530 >Subject: [WebMacro-user] The new map syntax > > > >>I like the new #set $map = { k1: v1, k2:v2 } syntax. The only problem >>is >>that it does not use the "List Ordered" Map i.e. when I want to say >>render a select list from it, it shows things not in the order in >>which >>the map was defined. Is there a way where I can specify the >>implementation class to use? I use JDK 1.5 and would like to specify >>the LinkedHashMap. >> >> > >No, I don't believe this is possible. > >I'd say it's generally better not rely on the order of definition of map >elements. > >If you need ordering you can simply create 2 lists. It's not that pretty >but... > >Alternatively, and usually this makes sense for "human" use, you would >populate lists etc based on a sort order rather than listed order - so you >can just write a trivial helper to return a sorted list of the keys: > >public class SortTool >{ > public static final Object sort(Object list) > { > List l = ListUtil.toList(list); > Collections.sort(l); > return l; > } >} > >...and use it like this: > >#set $sortedKeys = $Sorter.sort($myMap.keySet().iterator()) > >...of course you can make the usage of this tool a LOT nicer by adding >some more intelligence / overidden methods: > >public class SortTool >{ > public static final Object sort(Object list) > { > List l = ListUtil.toList(list); > Collections.sort(l); > return l; > } > > public static final Object sortKeys(Map map) > { > return sort( map.keySet().iterator()); > } >} > >...and use it like this: > >#set $sortedKeys = $Sorter.sortKeys($myMap) > > >Cheers > > > >------------------------------------------------------- >This SF.Net email is sponsored by the JBoss Inc. Get Certified Today >Register for a JBoss Training Course. Free Certification Exam >for All Training Attendees Through End of 2005. For more info visit: >http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click >_______________________________________________ >Webmacro-user mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/webmacro-user > >