布朗瑟正在显示一个糟糕的单选按钮顺序。我不知道为什么变化显示顺序。
Actually is showing this(WRONG)
以棕色表示的代码(错误):
<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";
}
答案 0 :(得分:0)
如果要维护在cargarFacturas方法中添加条目的顺序,请将Map实现从HashMap更改为LinkedHashMap。当您遍历Map值时,HashMap不会按插入顺序检索元素。这些值是以随机方式获取的。
使用
Map<String,String> listafacturas = new LinkedHashMap<String,String>();
而不是
Map<String,String> listafacturas = new HashMap<String,String>();