Bug 3146 - input:select does not preserve order
Summary: input:select does not preserve order
Status: CLOSED WONTFIX
Alias: None
Product: Taglibs
Classification: Unclassified
Component: String Taglib (show other bugs)
Version: 1.0
Hardware: PC Linux
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-08-16 06:57 UTC by Paul Hettl
Modified: 2005-03-01 04:38 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Hettl 2001-08-16 06:57:25 UTC
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();
Comment 1 Shawn Bayern 2001-08-16 07:22:46 UTC
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?