1

我是 Java 和 Springs 框架的新手。这是我的问题,由 n00b 提出(对不起,如果我听起来像二年级学生)。我试图让一个选择下拉列表出现在我的表单上,其中包含可选国家列表。数据存储在 MySQL 表中,并包含带有国家名称的单个列。我显然做错了什么。我希望这只是一个我缺少的简单事情引起的错误。提前感谢您的帮助。

我们正在使用 WebFlow。我的流 XML 中有以下内容:

<on-start>
  <evaluate expression="flowControllerActions.retrieveMBSAddressInfo()" result="address" />
  <evaluate expression="flowControllerActions.retrieveCountryInfo()" 
       result="flowScope.countryListing" />
</on-start>

retrieveCountryInfo() 看起来像这样:

public Map<String, String> retrieveCountryInfo() throws IOException {
    LOGGER.debug("inside retrieveMBSAddressInfo");
    Map<String, String> countryInfo = (Map<String, String>) coaService.getCountryInfo();
    return countryInfo;
}

coaService.getCountryInfo() 看起来像这样:

   public Map<String, String> getCountryInfo() {
        ArrayList <Country> cList = coaDao.getSelectableCountries();
        LinkedHashMap<String, String> retval = new LinkedHashMap<String, String>();
        for ( Country c : cList){
            retval.put(c.getName(), c.getName());
            log.debug(c.getName());
        }
        return retval;
    }

填充列表的coaDao.getSelectableCountries()看起来是这样的:

@SuppressWarnings("unchecked")
@Transactional(readOnly=true, propagation=Propagation.REQUIRED)
public ArrayList<Country> getSelectableCountries() {
    String myLike = "%";

    Session mySession = sessionFactory.getCurrentSession();

    ArrayList<Country> countries = (ArrayList<Country>) mySession
        .createCriteria(Country.class)
            .add(Restrictions.like("name", myLike)).list();

    return countries;
}

最后,JSP 页面尝试像这样呈现 select 元素:

<td>
    <form:select path="country" id="country">
        <form:options items="${countryListing}"/>
    </form:select>
</td>
4

1 回答 1

0

我不确定,但尝试这样的事情,

<td>
<form:select path="country" id="country">
    <c:forEach items="${countryListing}" var="countryMap" varStatus="status">
    <option value="${countryMap.key}">${countryMap.value}</option>
</c:forEach>
</form:select>

我希望这行得通!:)

于 2012-12-07T12:39:11.583 回答