2013-03-16 109 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