form:radiobuttons 列表顺序错误

form:radiobuttons wrong list order

Brownser 显示的单选按钮顺序不正确。我不知道为什么更改显示顺序。

I want this

Actually is showing this(WRONG)

brownser 中显示的代码(错误):

<input id="sdh.iesdfact1" name="sdh.iesdfact" type="radio" value="3"/>
<label for="sdh.iesdfact1">Con facturas</label>

<input id="sdh.iesdfact2" name="sdh.iesdfact" type="radio" value="2"/>
<label for="sdh.iesdfact2">Facturas requeridas</label>

<input id="sdh.iesdfact3" name="sdh.iesdfact" type="radio" value="1" checked="checked"/>
<label for="sdh.iesdfact3">Sin facturas</label>

应用代码:Jsp代码:

<label for="sdh.iesdfact”> <spring:message code="sdh.sol.fac"/></label>
        <form:radiobuttons path="sdh.iesdfact" items="${lista_facturas}" />

应用代码:Java代码:

 public static Map<String,String> cargarFacturas(MessageSource messageSource, Locale locale) {
       Map<String,String> listafacturas = new HashMap<String,String>();
       listafacturas.put("1","Sin facturas”);
       listafacturas.put("2","Facturas requeridas”);
       listafacturas.put("3","Con facturas”);
    return listafacturas;
    }

    @RequestMapping("/alta")
    public String alta(Model model, HttpServletRequest request, Locale locale)throws Exception{
      AltaForm altaForm = new AltaForm();               
      model.addAttribute("lista_facturas",Utilidades.cargarFacturas(messageSource, locale));
      model.addAttribute("altaForm", altaForm);
      return "alta";
    }   

如果您想保持在 cargarFacturas 方法中添加条目的顺序,请将 Map 实现从 HashMap 更改为 LinkedHashMap.When 您遍历 Map 值 HashMap 不会按元素的顺序检索元素插入。这些值以随机方式获取。

使用

Map<String,String> listafacturas = new LinkedHashMap<String,String>();

而不是

Map<String,String> listafacturas = new HashMap<String,String>();