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

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

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

    隨筆-72  評論-63  文章-0  trackbacks-0
    總結一下關于web上使用下拉框的情況

    從數據庫中獲得數據List,將數據放到Request里面
    ????????使用setAttribute(”AList”,AList)
    A中有2個屬性(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的標簽
    <html:select property=”xxx”>
    <html:options collection="AList" labelProperty="value" property="id" />
    </html:select>

    查一下struts的api文檔,可以看到select 中選項有3 taglib可以使用。
    第一種直接使用把所有選項寫在中間。
    <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>


    第二種:把選項放在一個Collection中(這里使用List).在實際項目中,更多的是可能數據來源于db,文件等。這種情況用得比較多。

    <html:options collection="AList" property="value" labelProperty="label"/>
    把option放在list中的過程在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 的一個屬性.
    <html:optionsCollection property="AList" />
    在Form 中添加AList 的setter和getter. Form中作如下處理。
    //the list can be a form property.
    f.setAgeList(AList);

    1.????????從數據庫中獲得數據,你應該在Action里面取得數據后,將數據放到Request里面
    2.????????數據取出來后放在一個List或Collection或Map里面,我習慣用List
    3.????????從List或其它的容器中取數據應該用<html:options> 或<html:optionsCollection>
    4.????????<html:options> 和<html:optionsCollection>外層必須用<html:select property="">,所以這個屬性你必須在FormBean里定義
    5.????????由于你要用到這些標簽,所以你必須定義FormBean
    6.????????
    從Action取數據,以List為例

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

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


    補充一點點:

    因為數據你要從 數據庫去取, 所以一般在 action 里調用 DAO ,作為 request 的一個屬性傳到頁面上; 這時一般用 <html:options .../> 標簽

    另外,如果數據不從數據庫去取,而是代碼固定的,則一般把這種放到 ActionForm 里,作為屬性在頁面上取,這時一般用 <html:optionsCollection ... />
    posted on 2006-07-10 13:52 船長 閱讀(445) 評論(0)  編輯  收藏 所屬分類: J2EE
    主站蜘蛛池模板: 国产美女a做受大片免费| 美女视频黄是免费的网址| 亚洲欧洲中文日韩av乱码| 亚洲精品无码久久| 热99re久久免费视精品频软件| 亚洲国产精品yw在线观看| 色老头永久免费网站| va天堂va亚洲va影视中文字幕 | 久久久久国色AV免费观看| 亚洲а∨天堂久久精品| 有色视频在线观看免费高清在线直播| 亚洲AV永久无码精品一福利| 久久午夜夜伦鲁鲁片免费无码 | 国产精品亚洲一区二区三区在线 | 精品久久久久久亚洲精品| 永久免费毛片在线播放| 在线a亚洲老鸭窝天堂av高清| 啦啦啦在线免费视频| 免费一区二区无码视频在线播放| 亚洲精品国产精品乱码不卡| a成人毛片免费观看| 国产精品免费看久久久久| 一级毛片免费播放试看60分钟| 亚洲精品无码久久久久去q| 99xxoo视频在线永久免费观看| wwwxxx亚洲| 久久影视综合亚洲| 一进一出60分钟免费视频| 亚洲成色在线综合网站| 免费可以看黄的视频s色| 老司机亚洲精品影院在线观看| 国产亚洲精品久久久久秋霞| 100部毛片免费全部播放完整| 日韩亚洲综合精品国产| 国产精品国产亚洲精品看不卡| 免费无码又黄又爽又刺激| 国产99久久久久久免费看| 亚洲а∨天堂久久精品| 日韩免费人妻AV无码专区蜜桃| 亚洲一区二区三区在线观看网站 | 免费a在线观看播放|