Spring MVC中的radiobuttons列表

时间:2015-10-17 06:23:56

标签: java spring spring-mvc

我有一个表格,将用户的姓名和性别作为输入数据。事实上,这种形式的输入是用性别命名的。我的bean代码是:

public class Info{
  private List<String> names;
  private List<Sex> sexes;
}

public enum Sex{
 Male,
 Fmale,
 Unknone;
 //
}

现在我想形成这样的

  <c:forEach begin="0" end="10" varStatus="s">
    <tr>
      <td> <form:input path="names[${s.index}]" /> </td>
      <td><form:radiobutton path="sexes" value="<%=Sex.Male%>"></td> 
      <td><form:radiobutton path="sexes" value="<%=Sex.Fmale%>"></td> 
      <td><form:radiobutton path="sexes" value="<%=Sex.Unknone%>"></td> 
    </tr>
  </c:forEach>

但是当运行项目时捕获此异常

   org.springframework.beans.NullValueInNestedPathException: Invalid property ... 

1 个答案:

答案 0 :(得分:1)

试试这个

    <c:forEach begin="0" end="10" varStatus="s">
<tr>
  <td> <form:input path="names[${s.index}]" /> </td>
  <td><form:radiobutton path="sexes[${s.index}]" value="<%=Sex.Male%>"></td> 
  <td><form:radiobutton path="sexes[${s.index}]" value="<%=Sex.Fmale%>"></td> 
  <td><form:radiobutton path="sexes[${s.index}]" value="<%=Sex.Unknone%>"></td> 
</tr>