In every tutorial I read that covers the struts2 validation or workflow interceptor, the examples given are very basic and assume every form field has a fixed name and is predefined in the .jsp file. E.g.:
<s:form method="post" validate="true">
<s:textfield label="Name" name="name"/>
<s:textfield label="Age" name="age"/>
<s:textfield label="Favorite color" name="answer"/>
<s:submit cssClass="btn btn-primary"/>
</s:form>
However, I currently have a form that is dynamically created by using javascript. When the page loads, ajax is used to fetch a list of countries (and metadata of those countries) from a database. A dropdown box is populated with the names of these countries. For each country, some input fields will be generated and added to the DOM, but these remain hidden until a country is selected. These inputs have id's such as:
france_extra_data_1
france_extra_data_2
france_extra_data_3
germany_extra_data_1
germany_extra_data_2
america_extra_data_1
america_extra_data_2
america_extra_data_3
america_extra_data_4
... and so on
When the user select a country, for example america, the inputs with id that have america in their name will be shown. the others remain hidden. The country america will NOT always have exactly 4 inputs associated with it. The reason why all inputs are generated on the spot and not just when the appropiate country is selected is because all inputs have a placeholder text and I do not want fetch this data from the database EVERY time, but just once when the page loads.
The problem is when I want to validate this form with struts2. Validators require knowledge of the name of the field, but I do not know beforehand how many inputs there will be (depends on the database) and I also do not which fields should be validated and which should be ignored (in the example above, only inputs with id's america).
Can the struts2 framework solve this problem?
I already read this question: dynamic field name for field validator in struts2, but I do not need a visitor field validator!