This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes indexed values in the correct order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "indexed values in the correct order" Watch "indexed values in the correct order" New topic
Author

indexed values in the correct order

Erik Panzer
Greenhorn

Joined: Aug 05, 2008
Posts: 3
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 ]
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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 !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Erik Panzer
Greenhorn

Joined: Aug 05, 2008
Posts: 3
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

Joined: Aug 05, 2008
Posts: 3
yo Sagar,

maybe deque is the problem (i thought it would be queue) but i also tried PriorityQueue and it didn't work correctly
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: indexed values in the correct order
 
Similar Threads
Picklilst to Picklist control
How to move array item from top of list to bottom of list
Protected in subclasses
Hibernate multiple one-to-many relationships to the same class
Indexed Properties Help