1
I’m having trouble finding a way to popular a dropdown in 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 that was already.
I’m doing it this way (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 make a POST request on the page my dropdown loads again, I am unable to recover the value I was.