2013-03-16 112 views
0

比方说,我有一个填充在选择框中的国家/地区列表,如下所示。选择包含所选项目的框

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

countryListitems属性的EL是List<Country> - Country指休眠实体。

我需要根据countryId提供的选择适当的国家,以便生成的HTML大致如下所示。

<select name="country"> 
    <option value="">--Please Select</option> 
    <option value="1">Austria</option> 
    <option value="2" selected="selected">United Kingdom</option> 
    <option value="3">United States</option> 
</select> 

在这种情况下,英国是选定的国家。没有使用JSTL的<c:foreach>循环,有没有可能?

我使用Spring 3.2.0。

回答

1

您需要在动作类中声明变量country。然后将setter和getters设置为您的值,然后在动作类中设置您的值。但是选择框路径名和变量名必须相同。

see here例如

+0

完成了。谢谢。 – Tiny 2013-03-16 05:50:01