velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Becker" <mbec...@webelite.com>
Subject foreach in reverse?
Date Thu, 20 Mar 2003 15:22:32 GMT
Hi,

I need some help with a Velocity foreach problem.  Or it might be a Java Hashtable/Set problem,
I'm not sure...

My app includes a form that has a few SELECT fields that are built from lookup tables in the
database.

I have a method in the controller "getCategoryList()" that does the lookup, and returns a
Hashtable that maps the names of each category to its Primary Key ID in the database.  (ID
is key of Hashtable, names are Values.)  Then, to build the SELECT field, I'm doing this:

<TD><SELECT NAME="category_id">
    #set ( $categoryList = $controller.getCategoryList() )
    #foreach ( $categoryId in $categoryList.keySet() )
        <OPTION VALUE="$!categoryId">$!categoryList.get($categoryId)</OPTION>
    #end
    </SELECT>
</TD>

This is working, but for some reason, it's printing the list out in reverse order!  (I.E.
from highest $categoryId to lowest.)

Is there any way for me to turn this around?  I've already tried using ORDER BY statements
in the SQL, and that doesn't seem to make a difference...

MEB


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message