I'm trying to save the data of a dynamic form in a map whose value is a list of objects, the problem is that when I get to the corresponding POST
method, in the map, the entryKey
are all right with their corresponding objects but when I look at the value table
of the map which should be filled appear as null
.
The map is as follows, I initialize it before processing the data:
private Map<String, List<FilterForm>> filtros = new LinkedHashMap<String, List<FilterForm>>();
public CustomSearchForm() {
this.filtros.put("datos_personales", new ArrayList<FilterForm>());
this.filtros.put("datos_institucion", new ArrayList<FilterForm>());
}
Before recieving the data, I set the lists with all the fields.
public void setDefaultFilters(SearchService ss) {
SearchType type = (SearchType) ss.findTypeById(searchType);
this.searchTypeName = type.getName();
FilterForm filterForm = null;
SearchTable table = (SearchTable) ss.findTableByAlias(searchTable, searchType);
List<FilterForm> filters = new ArrayList<FilterForm>();
for (SearchField field : table.getFields()) {
filterForm = new FilterForm(field.getName(), field.getAlias(), field.getF_type().getName());
filters.add(filterForm);
}
if (searchTypeName.equals(Constantes.SEARCH_TYPE_PERSONAS)) {
switch (searchTable) {
case "Datos personales":
this.filtros.get("datos_personales").addAll(filters);
break;
case "Formas de contacto":
this.filtros.get("p_formas_contacto").addAll(filters);
break;
case "Instituciones":
this.filtros.get("p_instituciones").addAll(filters);
break;
case "Relaciones":
this.filtros.get("p_relaciones").addAll(filters);
break;
case "Patronos":
this.filtros.get("p_patronos").addAll(filters);
break;
case "Candidatura":
this.filtros.get("p_candidatura").addAll(filters);
break;
}
} else if (searchTypeName.equals(Constantes.SEARCH_TYPE_INSTITUCIONES)) {
switch (searchTable) {
case "Datos de la institución":
this.filtros.get("datos_institucion").addAll(filters);
break;
case "Candidatura":
this.filtros.get("i_candidatura").addAll(filters);
break;
case "Formas de contacto":
this.filtros.get("i_formas_contacto").addAll(filters);
break;
case "Patronos":
this.filtros.get("i_patronos").addAll(filters);
break;
case "Empleados":
this.filtros.get("i_empleados").addAll(filters);
break;
}
}
}
And I collect the data in the following way:
<div class="col-md-2 col-xs-2">
<select th:id="'accion_'+${f.key}+'_'+${status.index}" onchange="cambioCombo(this);" th:if="${ff.tipoCampo != 'Booleano'}" class="form-control select2me" form="customSearch"
placeholder="Acción"
th:field="*{filtros[__${f.key}__][__${status.index}__].accion}">
<option th:each="a : ${customSearch.ACCIONES}" th:value="${a}"
th:text="${a}"></option>
</select>
</div>
<div class="col-md-3 col-xs-3">
<input th:id="'valueField_'+${f.key}+'_'+${status.index}" th:if="${ff.tipoCampo == 'Numero' or ff.tipoCampo == 'Texto' or ff.tipoCampo == 'Tabla'}" form="customSearch"
type="text" class="form-control" placeholder="Valor"
th:field="*{filtros[__${f.key}__][__${status.index}__].value}" />
<div th:if="${ff.tipoCampo == 'Fecha'}" th:id="'dateField_'+${f.key}+'_'+${status.index}" class="date"
data-date-format="dd/mm/yyyy">
<input form="searchForm"
class="form-control input-lg date" th:id="'valueFieldDate_'+${f.key}+'_'+${status.index}"
th:field="*{filtros[__${f.key}__][__${status.index}__].value}"
th:name="'valueField_'+${f.key}+'_'+${status.index}" type="text" placeholder="Fecha" />
</div>
The variable f
comes out of iterating the corresponding hashmap and the variable status
of iterating the list within that map.