頁面中經(jīng)常用到下拉列表,下面是個人對于STRUTS中標(biāo)簽使用的一點(diǎn)總結(jié):
STRUTS中的下拉選擇列表標(biāo)簽必須嵌套在<html:form>標(biāo)簽中,包括:
1.<html:select>
2.<html:option>
3.<html:options>
4.<html:optionsCollection>
使用時(shí)嵌套如下:
<html:select property="ationForm.property">
<html:option>或<html:options>或<html:optionsCollection>
</html:select>
其中property為ActionForm中對應(yīng)的一個屬性.
1.<html:option>
<html:option value="value">displayName</html:option>
其中value為實(shí)際使用的值(賦值到ActionForm對應(yīng)的屬性中) displayName頁面中顯示的信息.
例:<html:option value=""></html:option>顯示一個空白選擇,值為"".
2..<html:options>
<html:options collection="collection" labelProperty="displayName" property="value"/>
其中collection為一個集合,一般是個ArrayList,displayName為前臺顯示的名稱,value為后臺實(shí)際使用的值.
例:<html:options collection="arrayList" labelProperty="name" property="id" />
3..<html:optionsCollection>
<html:optionsCollection property="actionForm.property" label="displayName" value="value"/>
其中property為ActionForm中的一個屬性,為一個集合.displayName為前臺顯示的名稱,value為后臺實(shí)際使用的值.
例:<html:optionsCollection property="listProperty" label="name" value="id" />
補(bǔ)充一點(diǎn):如果要從 數(shù)據(jù)庫去取數(shù)據(jù),一般是在 action 里調(diào)用 DAO ,把結(jié)果存入一個ArrayList作為 request 的一個屬性傳到頁面上; 這時(shí)一般用 <html:options .../> 標(biāo)簽.另外,如果數(shù)據(jù)不從數(shù)據(jù)庫去取,而是代碼固定的,則一般把這種放到 ActionForm 里,作為屬性在頁面上取,這時(shí)一般用 <html:optionsCollection ... /> .