I have the following model
and I have a form with 4 combos that are filled with the same catalog CatalogoPerdida
and a button guardar
, when clicking on this button I must insert in the table PerdidaTiempo
, but I must insert 4 times, for the 4 combos that I have, or it depends if I fill them all, or only two, etc.
Now, I must also insert in this table the idTipoPerdida
, but how do I get that id? if I do not get it from a combo like the other catalog, how is the relationship to get that id?
Now, I have the following method in my controller that retrieves the id of the option that is selected in each combo, which would be the idCatPerdida
when clicking on the SAVE button
@ResponseBody
@RequestMapping(value= "/obtenerPerdidaTiempo", method=RequestMethod.POST)
public JsonResponse obtenerIds(@RequestBody PerdidaTiempo perdidaTiempo){
JsonResponse response = new JsonResponse();
response.setExito(0);
Integer idPrimerCombo = perdidaTiempo.getPrimerid();
Integer idSegundoCombo = perdidaTiempo.getSegundoid();
Integer idTercerCombo = perdidaTiempo.getTercerid();
Integer idCuartoCombo = perdidaTiempo.getCuartid();
return response;
}
I'm already setting up a service to do the insert and pass the parameters like this in the model, but my question is, how am I going to do the 4 inserts, or if they only fill two combos, do those 2 insert?
How can I implement that?
These are my combos and my SAVE button that sends a call to a function to send the data to the controller
<select class="form-control" id="primerId" name="primerId">
<option value="0" selected>Elije una opcion</option>
</select>
<select class="form-control" id="segundoId" name="segundoId">
<option value="0" selected>Elije una opcion</option>
</select>
<button type="button" class="btn btn-success" onclick="obtenerDatos()">Éxito</button>
I was thinking about doing validations with js, that if my combo1 is full and the other combos are not, then call a method that makes the insert with that id of the combo1, and so follow me, but they are many validations, you who think?
I hope you can help me, thanks