When creating a selection list with the input taglib the order of elements gets mixtes up. this is a problem in case of e.g. Month selection list. my workaround is: use two ArrayList object for values and lables: input.tld change: <attribute> <name>optionLabels</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>optionValues</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> code change: private ArrayList optionLabels ; // the lables private ArrayList optionValues ; // the submitted values public void setOptionValues(ArrayList x) { optionValues = x; } public void setOptionLabels(ArrayList x) { optionLabels = x; } in doStart(): // changed: // if ( optionLabels.size() != optionValues.size() ){ throw new JspException( "option keys and option values must be of equal size"); } HashMap options = new HashMap(); ListIterator lIter = optionLabels.listIterator(); int j = 0; while ( lIter.hasNext() ) { Object key = (Object) lIter.next(); Object value = (Object) optionValues.get( j); j++; options.put( key, value); } // actually print the <option> tags if (options.size() > 0 ) { //if (options != null) { Iterator i = optionLabels.iterator();
Order isn't intended to be preserved; you can use a TreeMap if you want an ordering against a Comparable, and you can also write a Map using a back-end Vector if you want to preserve order of entry. The key is to simplify the page author's usage; using two separate Lists won't necessarily do that. Thanks for the suggestion. Do you have another suggested mechanism that won't complicate usage?