0

I use Gaelyk framework on Google AppEngine.

from HTML form I need to get params in exact sequence.
Order of params is very important from my application.

I have HTML Form contans:

<input type="hidden" name="coins" value="50" />
<input type="hidden" name="coins" value="40" />
<input type="hidden" name="coins" value="30" />
<input type="hidden" name="coins" value="20" />
<input type="hidden" name="coins" value="10" />

After form submiting I got array:

// [50,40,30,20,10]
print params.coins

The array is in correct order, but can I depend on this behavior?

or if I need exact order, I need to write:

<input type="hidden" name="coins[0]" value="50" />
<input type="hidden" name="coins[1]" value="40" />
<input type="hidden" name="coins[2]" value="30" />
<input type="hidden" name="coins[3]" value="20" />
<input type="hidden" name="coins[4]" value="10" />

In servlet I got map:

// ['coins[3]':20,'coins[0]':50,'coins[1]':40,'coins[2]':30,'coins[4]':10]
print params

What is the correct solution?
If the second solution is correct, what is the best solution for obtaining Array from Maps?

Thanks a lot
Tom

Tomáš
  • 2,078
  • 3
  • 22
  • 21
  • I think your question really needs to be: "is the browser guaranteed to pass form parameters in the request in a specific order compared to the order in which they occurred in the document". If the answer to that is 'no', then you you don't even need to worry about what Gaelyk is doing. Of course, maybe you already know that answer... – csturtz Mar 01 '12 at 21:23

1 Answers1

1

According to this similar question, so long s the browser sticks to the specification, then the order can be relied upon.

If the browser doesn't stick to the specification obviously, you'll need to go with option[2]

Community
  • 1
  • 1
tim_yates
  • 167,322
  • 27
  • 342
  • 338