Im programming a system that generates forms based on input of the user I will know only at runtime what will be displayed. The problem with this is that its difficult to give a name to, lets say, a textbox and then be able to access its value in a subsequent page using the param variable.
At runtime, the user selects the participants of a tournament. Then a new page is displayed with all the names of the selected players plus a textbox (or more than one textbox, depending on the amount of rounds to be played) that allows the user to fill in the score/s of the participants.
How can these elements be accessed in a following page that will for example verify this input or save it to a database? Preferably a solution using JSP / JSTL only, no servlet.
Thanks for any help!
I think you need to explicitly associate each textbox with however the participant is identified in your system. Suppose each participant has a unique integer id. Then you can name the textboxes "score-345", "score-284", etc. When the request comes in, iterate thru the available parameter names and strip off the id from the name. Alternatively, you can just name them "score-1", score-2", etc., and keep a seperate list of the corresponding id's. The list would be a hidden form variable (CSV format), although I'm not sure the indirection buys you much. If you don't like exposing database id's you can use an encoding scheme to generate the names and recover the id's by decoding them when request comes in. In any case, one class can be used by both pages that contains the forward and reverse algorithms for generating names from id's and vice-versa, so the pages shouldbe able to stay in sync.
Thanks for you reply. Could you give me an example code snippet on how to iterate through the (unknown) parameter names?