how to fill a combo using an enum, with spring?

0

I have the following enum

public enum TipoMovimientos {

MOVIMI_ALTA(1L,"ALTA"),
MOVIMI_BAJA(2L,"BAJA"),
MOVIMI_EXTEM(3L,"EXTEMPORANEO");



private Long idTipoMov;
private String descTipoMov;

private TipoMovimientos(Long idTipoMov, String descTipoMov) {
    this.idTipoMov = idTipoMov;
    this.descTipoMov = descTipoMov;
}

}

and I want to show those three options within a combo, this is my controller that directs me to the page

@RequestMapping(value= "/views/consulta", method = RequestMethod.GET)
public String redireccionaConsultaPage(Locale locale, Model model) {
        model.addAttribute(Constantes.CONSULTA_FORM, new Consulta());
        return Constantes.CONSULTA_VISTA;
}

but I do not know how to make it visualize, it must be inside a controller method?

this is my combo

<select id="tipoMov" class="form-control" data-toggle="tooltip" 
        data-placement="right" title="Movimientos" name="tipoMov">
</select>
<span class="error" path="tipoMov"></span>
    
asked by Root93 01.06.2018 в 04:40
source

1 answer

0

In the controller add the Enum to the model:

model.addObject("tipoMovimientos", TipoMovimientos.values());

In the jsp:

<form:select path="selection">
    <form:options items="${tipoMovimientos}" itemValue="idTipoMov" itemLabel="descTipoMov"/>
</form:select>
    
answered by 01.06.2018 в 11:23