Search code examples
htmljerseyjava-ee-6

How to handle dynamic number of form elements in javaee6


Normally we have a static form that is posted on the server and since it's static we know the name of the variables.

But let's say I have a dynamic number of form elements that I need to post, what's the best way to handle it in the backend? Can it be done via jersey?

A best example of this, is paypal's implementation when checking out items. They have dynamic number of inputs that is suffixed with _x, where x is a number.

<form>
<input type="text" name="name_1" />
<input type="text" name="amount_1" />
<input type="text" name="quantity_1" />

<input type="text" name="name_2" />
<input type="text" name="amount_2" />
<input type="text" name="quantity_2" />
</form>

How do I read all the input text in the backend?

Thanks,
czetsuya


Solution

  • you can read entity as MultivaluedMap<String, String> form or Form form (which is basically same thing) and iterate all keys or .. whatever you need. See FormParamTest for example.