• 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

indexed values in the correct order

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a problem that is confusing me. In my JSP I'm using indexed properties with an array index in the end of the input name, like name[0], name[1], name[2] and so on.

i'm accessing it in my form bean the common way by using bean utils method

setName(int index, String inputString) {
nameList.add(inputString);
}

nameList is a LinkedList of Strings.

The problem is that the values are saved in the wrong order so that in my jsp name[0] is "Alpha", name[1] is "Beta" and name[2] "Gamma" but when i iterate over the list later the results are "Beta", "Gamma", "Alpha" or something like that.

This is really bad 'cause i need to save the properties in the correct order they are in the jsp.

Is there a simple solution to this?

Thanks in advance, Erik
[ August 05, 2008: Message edited by: Erik Panzer ]
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There should not be any order problem , because the LinkedList implements the Deque interface. Still give it just try to change it from LinkedList to ArrayList class !
 
Erik Panzer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
found the solution the moment i submitted

I use ArrayList instead of LinkedList an then access the index directly.

public void setName(int index, String inputString) {
while (index >= nameList.size()) {
nameList.add(new String());
}
this.nameList.set(index, inputString);
}
 
Erik Panzer
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yo Sagar,

maybe deque is the problem (i thought it would be queue) but i also tried PriorityQueue and it didn't work correctly
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic