神秘的 J2ee 殿堂

          ·古之學(xué)者必有師·做學(xué)者亦要做師者·FIGHTING·

          jsp通過logic:iterate或html:optionsCollection循環(huán)顯示action中傳過來的對(duì)象List

          action中代碼如下:
                  List allUser=this.getLoginServiceImpl().find();
                  request.setAttribute(
          "user", allUser);
                  
          return mapping.findForward("listUser");
          注:其中User對(duì)象有id和name屬性

          jsp顯示:法一
                      <html:select property="school">
                      
          <html:option value="">
                          
          <bean:message key="login.select" />
                     
          </html:option>
                          
          <logic:present name="user">
                              
          <logic:iterate id="user" name="user" offset="0">
                                  
          <option value="<bean:write name="user" property="id" />">
                                      
          <bean:write name="user" property="name" />
                                  
          </option>
                              
          </logic:iterate>
                          
          </logic:present>
                  
          </html:select>
          jsp顯示:法二
                 <html:select property="school">
                     
          <html:optionsCollection name="user" value="id" label="name"/>
                 
          </html:select>

          optionsCollection標(biāo)簽用法:
          與options標(biāo)簽一樣,optionsCollection標(biāo)簽可以從集合或者是包含集合的對(duì)象里獲得選項(xiàng)的標(biāo)簽/值對(duì)。在這兩種情況里,集合或包含集合的對(duì)象必須是一個(gè)作用域?qū)ο螅駝t定制標(biāo)簽將無法訪問它。

          1.與包含集合的對(duì)象配合使用
          舉例:userForm動(dòng)作表單有一個(gè)如下所示的ArrayList類型的userList屬性,相應(yīng)的set,get方法,通過在action中設(shè)置好userForm后,request.setAttribute("userForm",userForm);
          在jsp頁面:
          <html:select property="school">
          <html:optionsCollection name="userForm"
                property
          ="userList"/>
          </html:select>

          2.與集合配合使用
          action中
          ArrayList userList=new ArrayList();
          userList.add(
          new LabelValueBean("1","haha"));
          userList.add(
          new LabelValueBean("2","dada"));
          userList.add(
          new LabelValueBean("3","xiaoxiao"));
          request.setAttribute(
          "userList",userList);
          jsp頁面
          <html:select property="school">
          <html:optionsCollection name="userList"
                label
          ="label" value="value"/>
          </html:select>

          (注:邊學(xué)邊share,如有問題,歡迎交流學(xué)習(xí))


          posted on 2007-09-15 23:58 月芽兒 閱讀(6485) 評(píng)論(3)  編輯  收藏 所屬分類: J2EE學(xué)習(xí)心得

          評(píng)論

          # re: jsp通過logic:iterate或html:optionsCollection循環(huán)顯示action中傳過來的對(duì)象List 2008-03-26 20:11 李曉勇

          今天剛好碰上類似問題,此文幫我解開了疑惑,多謝!!!  回復(fù)  更多評(píng)論   

          # re: jsp通過logic:iterate或html:optionsCollection循環(huán)顯示action中傳過來的對(duì)象List 2009-05-09 13:07 過冬的kimera

          幫大忙了,謝謝  回復(fù)  更多評(píng)論   

          # re: jsp通過logic:iterate或html:optionsCollection循環(huán)顯示action中傳過來的對(duì)象List 2012-05-30 15:25 cowrylee

          <option value="<bean:write name="user" property="id" />">
          這種寫法不符合xhtml  回復(fù)  更多評(píng)論   

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          相冊(cè)

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 垦利县| 蒲江县| 冀州市| 修武县| 栖霞市| 克山县| 曲松县| 扬中市| 上高县| 平江县| 禹城市| 汝阳县| 涡阳县| 建平县| 湾仔区| 通化县| 永济市| 昆明市| 淮阳县| 昌平区| 中超| 进贤县| 视频| 奈曼旗| 册亨县| 和田市| 左权县| 穆棱市| 鄂州市| 日照市| 宁都县| 松滋市| 嘉定区| 穆棱市| 顺平县| 榆中县| 南溪县| 松滋市| 遵化市| 大荔县| 岑溪市|