【问题标题】:Display spring model list as simple fields将弹簧模型列表显示为简单字段
【发布时间】:2011-07-25 07:50:59
【问题描述】:

可以绑定一个字符串列表(List),并在jsp中的组合框中显示,如下所示:

<form:select path="countryId">
    <form:option value="" label="Please Select"></form:option>
    <form:options items="${countryList}" itemValue="countryId" itemLabel="countryName"/>
</form:select>

我希望此列表显示在 &lt;td&gt;&lt;form:input&gt; 类似字段中,而不是组合框中。

我将模型中的字符串列表绑定为

Map referenceData = new HashMap();
referenceData.put("OutputsList", Outputs);

在 JSP 中我使用

<c:forEach var="OutputsList" items="${Outputs}">  
    ${OutputsList}
</c:forEach>

但没有打印列表。可能是什么原因?

【问题讨论】:

    标签: java forms spring jsp tags


    【解决方案1】:

    那样做。

    <c:forEach var="country" items="${countryList}">
      <tr>
        <td>${country.countryId}</td>
        <td>${country.countryName}</td>
      </tr>
    </c:forEach>
    

    在服务器端使用 ModelAndView 对象

    List<Country> countryList;
    ModelAndView mv = new ModelAndView("index");
    mv.addObject("country",countryList);
    

    【讨论】:

    • 感谢您的回复。我修改了我的问题。请再看一遍。
    【解决方案2】:

    在 jsp 中使用时出现了错误的方法。从有问题的代码中只需交换 OutputsList

    Map referenceData = new HashMap();
    referenceData.put("OutputsList", Outputs);
    

    在 JSP 中我使用

    <c:forEach var="item" items="${OutputsList}">  
        ${item}
    </c:forEach>
    

    它会起作用的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2016-08-23
      • 2023-03-09
      • 1970-01-01
      • 2013-07-28
      • 1970-01-01
      相关资源
      最近更新 更多