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

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

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

    posts - 89,  comments - 98,  trackbacks - 0
      html:options是Struts中比較復(fù)雜的一個tage lib,用法靈活,但是Sturts提供的源碼exercise taglib中沒有提出常用jsp+ActionForm這樣形式的最直接的總結(jié),現(xiàn)從中總結(jié)如下,分兩種情況:數(shù)組和Collection。
      
      需求,要達到:
      <select name="beanCollectionSelect" multiple="multiple" size="10">
      <option value="value 0">Label 0</option>
      <option value="value 1" selected="selected">Label 1</option>
      <option value="value 2">Label 2</option>
      <option value="value 3" selected="selected">Label 3</option>
      <option value="value 4">Label 4</option>
      <option value="value 5" selected="selected">Label 5</option>
      <option value="value 6">Label 6</option>
      <option value="value 7">Label 7</option>
      <option value="value 8">Label 8</option>
      <option value="value 9">Label 9</option></select>
      
      要實現(xiàn)上述效果,需要兩步:
      第一:設(shè)置ActionForm,
      也分兩小步:第一小步必須在ActionForm中,有一句
      private Collection beanCollection;
      public Collection getBeanCollection();
      
      Collection beanCollection要確保是一個實現(xiàn),如ArrayList,如果不是則會報No collection found的錯誤,Struts的最大不方便就是一旦出問題,定位很難,不知道什么地方使用錯誤,或忘記設(shè)置什么了。
      
      因為前面需求中option的value值和label值不一樣,那么在beanCollection中保存的就是一個value和label組成的對象,名為LabelvalueBean,在LabelvalueBean中有兩個屬性value和label,
      
      在程序某個地方要為beanCollection賦值,如:
      
      Vector entries = new Vector(10); 
      entries.add(new LabelvalueBean("Label 0", "value 0"));     
      entries.add(new LabelvalueBean("Label 1", "value 1"));     
      entries.add(new LabelvalueBean("Label 2", "value 2"));     
      entries.add(new LabelvalueBean("Label 3", "value 3"));     
      entries.add(new LabelvalueBean("Label 4", "value 4"));      
      entries.add(new LabelvalueBean("Label 5", "value 5"));     
       entries.add(new LabelvalueBean("Label 6", "value 6"));      
      entries.add(new LabelvalueBean("Label 7", "value 7"));      
      entries.add(new LabelvalueBean("Label 8", "value 8"));      
      entries.add(new LabelvalueBean("Label 9", "value 9"));
      
      然后執(zhí)行setBeanCollection(entries);
      這樣ActionForm中的beanCollection算有值了。
      第二小步,需要設(shè)置Selected,selected有兩種,單選和多選:
      在ActionForm中必須有:
      
      private String singleSelect = "Single 5"; 
      public String getSingleSelect()
       {
         return (this.singleSelect);
        } 
      public void setSingleSelect(String singleSelect)
       {
         this.singleSelect = singleSelect;
        }
      
      或多選,多選必須是數(shù)組:
      
      private String[] beanCollectionSelect = { "value 1", "value 3",
                             "value 5" }; 
      public String[] getBeanCollectionSelect() {
        return (this.beanCollectionSelect);  }
        public void setBeanCollectionSelect(String beanCollectionSelect[])
       {
          this.beanCollectionSelect = beanCollectionSelect;
        }
      
      第二:在Jsp中寫入tang lib語句如下:
      
      <html:select property="beanCollectionSelect" size="10" multiple="true">
          <html:optionsCollection name="testbean" property="beanCollection"/>  
       </html:select>
      
      其中testbean是ActionForm的名稱。
      
      以上是html:options的Collection解決方案,如果option值很少,簡單地可以實現(xiàn)為數(shù)組,兩步:
      第一:在ActionForm中,
      
      private String values[] =
         { "Magazine", "Journal", "News Paper","Other" }; 
      private String labels[] =
         { "L-Magazine", "L-Journal", "L-News Paper","L-Other"};
        private String selected = "Magazine";  
      public String getSelected()
      {
         return selected;
        }  
      public void setSelected(String selected)
      {
         this.selected = selected;
        } 
      public String[] getvalues()
      {
         return values;
        }  
      public void setvalues(String[] values)
      {   this.values = values;
        } 
      public String[] getLabels()
      {
         return values;
        }  
      public void setLabels(String[] labels)
      {
         this.labels = labels;
        }
      
      第二步在jsp中:
      
      <html:select property="selected" >     
      <html:options name="testbean" property="values" labelProperty="label"/>   </html:select>
      
      Struts標簽庫的使用還是需要小心,不必完全使用Struts的標簽庫,個人感覺Struts這種替代Html語句的標簽庫有一種牽強附會,給使用者掌握帶來難度,使用者除熟悉html外,還必須理解Struts的對應(yīng)標簽庫用法,而且這種調(diào)試出錯,問題也無法準確定位,總是抽象地告訴你,no bean 或no form
    posted on 2007-02-11 22:03 水煮三國 閱讀(681) 評論(0)  編輯  收藏 所屬分類: Struts
    <2007年2月>
    28293031123
    45678910
    11121314151617
    18192021222324
    25262728123
    45678910

    常用鏈接

    留言簿(4)

    隨筆分類(85)

    隨筆檔案(89)

    文章分類(14)

    文章檔案(42)

    收藏夾(37)

    java

    oracle

    Sybase

    搜索

    •  

    積分與排名

    • 積分 - 211827
    • 排名 - 266

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲午夜国产精品| 久久久久久久久亚洲| 国产亚洲精aa在线看| 99久久精品日本一区二区免费| 久久久无码精品亚洲日韩京东传媒 | 免费看污成人午夜网站| 久久久亚洲AV波多野结衣 | a毛片全部播放免费视频完整18| 亚洲日本韩国在线| 国产免费福利体检区久久| 红杏亚洲影院一区二区三区| yellow视频免费在线观看| 久久久久亚洲爆乳少妇无| 最近免费字幕中文大全| 久久久久久亚洲精品中文字幕| jjizz全部免费看片| 亚洲人AV在线无码影院观看| 免费鲁丝片一级在线观看| 美女18毛片免费视频| 亚洲爽爽一区二区三区| 久久精品视频免费| 亚洲国产成人久久三区| 黄网址在线永久免费观看 | 亚洲大成色www永久网址| 午夜a级成人免费毛片| 一级毛片在线免费播放| 亚洲成av人片天堂网| 久久99九九国产免费看小说| 国产亚洲一卡2卡3卡4卡新区| 亚洲一区二区三区乱码在线欧洲| 免费鲁丝片一级观看| aaa毛片免费观看| 亚洲人成电影青青在线播放| 最新69国产成人精品免费视频动漫| 亚洲av无码av在线播放| 色久悠悠婷婷综合在线亚洲| 亚洲免费网站在线观看| 国产成人综合亚洲| 色婷婷六月亚洲婷婷丁香| 波多野结衣久久高清免费 | 亚洲三级在线视频|