• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ordered select

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a select list with multiple options enabled (<select multiple> and up/down JavaScript to control the order. I'm trying to confirm or refute that calling request.getParameterValues() will return them in the order they are on the screen. It appears to preserve the order from a test.

How would I verify this is not coincidence? Does anyone either know the answer or know where I would look this up?
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
I have a select list with multiple options enabled (<select multiple> and up/down JavaScript to control the order. I'm trying to confirm or refute that calling request.getParameterValues() will return them in the order they are on the screen. It appears to preserve the order from a test.

How would I verify this is not coincidence? Does anyone either know the answer or know where I would look this up?



The ordering of the request parameters isn't required by the HTML specification, so webbrowsers and appservers doesn't need to respect it. Besides, the parameterMap in servlets is backed by a HashMap. You know, HashMaps does not guarantee the ordering of the items as is with the insertion order.

I would populate a hidden input element with the IDs/keys/whateveridentifiers of each item commaseparated in the desired order and base your logic on that instead.
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bauke Scholtz:
The ordering of the request parameters isn't required by the HTML specification, so webbrowsers and appservers doesn't need to respect it. Besides, the parameterMap in servlets is backed by a HashMap. You know, HashMaps does not guarantee the ordering of the items as is with the insertion order.


In other words, my test of this was incredibly lucky! Thank you for the reply. I wanted to be sure before writing any code either way. Using JavaScript to create a list of keys is no problem. I just didn't want to do it if it would be unneeded complexity.

Thanks Bauke!
reply
    Bookmark Topic Watch Topic
  • New Topic