Search code examples
gaelyk

HTML params as array


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


Solution

  • 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]