【问题标题】:form:radiobuttons wrong list order形式:单选按钮错误的列表顺序
【发布时间】:2016-03-17 11:25:55
【问题描述】:

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

I want this

Actually is showing this(WRONG)

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

<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";
    }   

【问题讨论】:

    标签: spring model-view-controller radio-button listitem


    【解决方案1】:

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

    使用

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

    而不是

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

    【讨论】:

      猜你喜欢
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多