Give them the same name so that instead of getRequestParameterValuesMap()
<input type="hidden" name="name" value="SomeValue1"> <input type="hidden" name="name" value="SomeValue2"> ...
String[] names = externalContext.getRequestParameterValuesMap().get("name");
It is guaranteed that the order will be the same as in the HTML DOM.
Alternatively, based on the suffix of the incremental integer, as in the HTML DOM, you can also just get the query parameter in a loop until null is returned.
List<String> names = new ArrayList<>(); for (int i = 1; i < Integer.MAX_VALUE; i++) { String name = requestParameterMap.get("name" + i); if (name != null) { names.add(name); } else { break; } }
source share