I'm having a hard time finding a way to populate a dropdown on the Controller and move on to the view. Because this way I'm doing when I enter the screen to update the dropdown does not return with the value it already was.
I'm doing this (controller):
@RequestMapping(value = { "/updateAgenda/{idAgenda}" }, method = RequestMethod.GET)
public ModelAndView update(@PathVariable("idAgenda") Integer idAgenda, Model atributos) {
ModelAndView model = new ModelAndView("agenda/atualiza-agenda");
Agenda agenda = agendaService.buscarAgendaPorId(idAgenda);
model.addObject("agenda", agenda);
atributos.addAttribute("destinos", destinoService.buscarTodosDestinos());
atributos.addAttribute("rotas", rotaService.buscarTodasRotas());
return model;
}
And in the view:
<form:select path="idDestinoAgendamento" class="form-control">
<option value="-1">Selecione o Destino</option>
<c:forEach items="${destinos}" var="destino">
<option value="${destino.idDestino}">${destino.nomeLocalDestino}</option>
</c:forEach>
</form:select>
My problem is that when I do a POST request on the page my dropdown loads again, I can not retrieve the value it was.