<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-200  評(píng)論-148  文章-15  trackbacks-0

    總結(jié)一下關(guān)于web上使用下拉框的情況

    從數(shù)據(jù)庫(kù)中獲得數(shù)據(jù)List,將數(shù)據(jù)放到Request里面
    ????????使用setAttribute(”AList”,AList)
    A中有2個(gè)屬性(String id,String value)

    1.????????使用JSTL的forEach方式
    <select name=”xx” ……..>
    <c:forEach items="${AList}" var="p" >
    ????????<c:choose>
    ????????????????<c:when test="${xxx == p.id}">
    ????????????????????????<option value='<c:out value="${p.id}"/>' selected="selected">
    ????????????????????????????????????????<c:out value="${p.value}"/>
    ????????????????????????</option>
    ????????????????</c:when>
    ????????<c:otherwise>
    ????????????????????????<option value='<c:out value="${p.id}"/>'>
    ????????????????????????????????<c:out value="${p.value}"/>
    ????????????????????????</option>
    ????????????????</c:otherwise>
    ????????</c:choose>????????
    <c:forEach>
    </select>

    2.????????使用struts的標(biāo)簽
    <html:select property=”xxx”>
    <html:options collection="AList" labelProperty="value" property="id" />
    </html:select>

    查一下struts的api文檔,可以看到select 中選項(xiàng)有3 taglib可以使用。
    第一種直接使用把所有選項(xiàng)寫(xiě)在中間。

    <html:option value="0-15">0-15</html:option>
    <html:option value="15-20" >15-20</html:option>
    <html:option value="20-30" >20-30</html:option>
    <html:option value="20 or above">30 or above</html:option>


    第二種:把選項(xiàng)放在一個(gè)Collection中(這里使用List).在實(shí)際項(xiàng)目中,更多的是可能數(shù)據(jù)來(lái)源于db,文件等。這種情況用得比較多。

    <html:options collection="AList" property="value" labelProperty="label"/>
    把option放在list中的過(guò)程在Action中作處理
    //prepare the age selector list.
    List ageList =new ArrayList();
    ageList.add(new LabelValueBean("0-15","0-15"));
    ageList.add(new LabelValueBean("15-20","15-20"));
    ageList.add(new LabelValueBean("20-30","20-30"));
    ageList.add(new LabelValueBean("30 or above","30 or above"));
    request.setAttribute("AList",AList);


    這里使用了LabelValueBean,可以不用的,象
    <html:options collection="AList" labelProperty="value" property="id" />
    只要在AList中填入的bean有value和id屬性就可以

    第三種,把此list 作為Form 的一個(gè)屬性.
    <html:optionsCollection property="AList" />
    在Form 中添加AList 的setter和getter. Form中作如下處理。
    //the list can be a form property.
    f.setAgeList(AList);

    1.????????從數(shù)據(jù)庫(kù)中獲得數(shù)據(jù),你應(yīng)該在Action里面取得數(shù)據(jù)后,將數(shù)據(jù)放到Request里面
    2.????????數(shù)據(jù)取出來(lái)后放在一個(gè)List或Collection或Map里面,我習(xí)慣用List
    3.????????從List或其它的容器中取數(shù)據(jù)應(yīng)該用<html:options> 或<html:optionsCollection>
    4.????????<html:options> 和<html:optionsCollection>外層必須用<html:select property="">,所以這個(gè)屬性你必須在FormBean里定義
    5.????????由于你要用到這些標(biāo)簽,所以你必須定義FormBean
    6.????????
    從Action取數(shù)據(jù),以L(fǎng)ist為例

    List list = xxxxx;//從數(shù)據(jù)庫(kù)中取得下拉列表中的數(shù)據(jù)
    request.setAttribute("list",list);

    在頁(yè)面顯示
    <html:form action="xxxx">
    ...
    <html:select property="xxx">
    <html:options collection="list" labelProperty="下拉框中顯示的內(nèi)容,一般是name或其它相似屬性" property="各選項(xiàng)對(duì)應(yīng)的值,一般是id" />
    </html:select>
    ...
    </html:form>


    補(bǔ)充一點(diǎn)點(diǎn):

    因?yàn)閿?shù)據(jù)你要從 數(shù)據(jù)庫(kù)去取, 所以一般在 action 里調(diào)用 DAO ,作為 request 的一個(gè)屬性傳到頁(yè)面上; 這時(shí)一般用 <html:options .../> 標(biāo)簽

    另外,如果數(shù)據(jù)不從數(shù)據(jù)庫(kù)去取,而是代碼固定的,則一般把這種放到 ActionForm 里,作為屬性在頁(yè)面上取,這時(shí)一般用 <html:optionsCollection ... />
    posted on 2006-07-20 16:11 無(wú)聲 閱讀(372) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 職場(chǎng)生活
    主站蜘蛛池模板: 岛国大片免费在线观看| 久久久久久国产a免费观看黄色大片 | 成年女人18级毛片毛片免费| 国产免费久久精品| 亚洲宅男天堂在线观看无病毒| 亚洲大尺度无码专区尤物| 久久精品国产亚洲AV无码偷窥| 亚洲精华国产精华精华液 | 亚洲成a人片在线观看国产| 亚洲国产精品lv| 国产精品日本亚洲777| 在线观看特色大片免费网站| 最近中文字幕mv免费高清在线| 国产免费人成视频在线观看| 亚洲AV无码精品国产成人| 日韩免费无码一区二区三区 | 亚洲精品无码一区二区| 国产日韩AV免费无码一区二区 | 亚洲视频精品在线观看| 美女视频黄频a免费| 免费A级毛片无码A∨免费| 亚洲国产综合人成综合网站| 亚洲国产美女在线观看| A级毛片高清免费视频在线播放| 久久噜噜噜久久亚洲va久| 一进一出60分钟免费视频| 国产va精品免费观看| 亚洲阿v天堂在线| 亚洲天堂2017无码中文| 久久久久免费看黄a级试看 | 成人av免费电影| 免费看一级一级人妻片| 好男人www免费高清视频在线| 久久亚洲精品视频| 91成年人免费视频| 亚洲综合久久1区2区3区| a毛片免费播放全部完整| 国产91精品一区二区麻豆亚洲| 亚洲一区二区无码偷拍| 日本妇人成熟免费中文字幕| 午夜亚洲WWW湿好爽|