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

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

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

    posts - 32,  comments - 149,  trackbacks - 0
    1. html:select

    該標簽生成一個select元素。multiple屬性決定是否為多選。如果指定了multiple="true"則為多選,此時對應的屬性應該是一個數組。否則,此時對應的屬性應該是標量。

    注意:為了正確的處理未作選擇的情況,在ActionForm中的reset()方法中必須將標量屬性設置為默認值而將數組的長度置為0。?另外的一個重要問題就是struts如何生成option元素了,這個任務struts交給了html:option、html:options和html:optionsCollection三個標簽。

    ??? 1)html:option

    ???? 該標簽生成一個HTML的option元素。該標簽必須嵌在html:select標簽中。它的顯示文本來自其標簽體,也可以來自于資源文件。

    eg. <html:option value="red">紅色</html:option>????

    ???? <html:option value="blue">藍色</html:option>

    ?? 2)html:options

    ???? 該標簽生成多個HTML的option元素。該標簽必須嵌在html:select標簽中。

    ???? 指定collection屬性的方式舉例如下:

      <html:select name="userForm" property="uid" size="1">  

    <html:options collection="userCollection" property="uid" labelProperty="uname"/>

    </html:select>

    ??? 未指定collection屬性方式的舉例如下:用數組的形式 String uids[] ,String unames[]

      <html:select name="userForm" property="uid" size="1">  

    <html:options property="uids" labelProperty="unames"/>

    </html:select>

    ??? 3)html:optionsCollection標簽

    ???? 該標簽生成多個HTML的option元素。其功能和html:options標簽的相同。
    ????? userForm 里有個List userlist 它通過這樣得到的?
    ???? userlist.add(new LabelValueBean("label1","value1"));

    ? <html:select name="userForm" property="uid" size="1">????
    ? <html:optionsCollection name="userForm" property="userlist">?
    ? </html:select>

    ?? 4)實現舉例

    ?? html:options是Struts中比較復雜的一個tage lib,用法靈活,但是Sturts提供的源碼exercise taglib中

    ?? 沒有提出常用jsp+ActionForm這樣形式的最直接的總結,現從中總結如下,分兩種情況:數組

    和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>
      
      要實現上述效果,需要兩步:
      第一:設置ActionForm,
      也分兩小步:第一小步必須在ActionForm中,有一句
      private Collection beanCollection;? //Collection 可以用List或者Vector
      public Collection getBeanCollection();
      Collection beanCollection要確保是一個實現,如ArrayList,
    ?? 如果不是則會報No collection found的錯誤,Struts的最大不方便就是一旦出問題,

    ?? 定位很難,不知道什么地方使用錯誤,或忘記設置什么了,不過可以查看tomcat Log的。
      
      因為前面需求中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"));
      
      然后執行setBeanCollection(entries);
      這樣ActionForm中的beanCollection算有值了。
      第二小步,需要設置Selected,selected有兩種,單選和多選:
      在ActionForm中必須有:
      
      private String singleSelect = "Single 5"; 
      public String getSingleSelect()
       {
         return (this.singleSelect);
        } 
      public void setSingleSelect(String singleSelect)
       {
         this.singleSelect = singleSelect;
        }
      
      或多選,多選必須是數組:
      
      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值很少,簡單地可以實現為數組,兩步:
      第一:在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中:
      //下面這個我使用時,出錯,總是提示找布道labels,不知什么原因?
      <html:select property="selected" >     
      <html:options name="testbean" property="values" labelProperty="labels"/> 
      </html:select>
    總結: 經過這段時間的開發和學習,自我感覺struts還是不錯的,雖然一開始的時候有點麻煩,

    不過其實Java的配置也是有點麻煩的,不過用了這么長時間的Java,現在覺得Java挺好的!

    posted on 2007-01-18 09:05 chunkyo 閱讀(4533) 評論(3)  編輯  收藏 所屬分類: openSource(struts&hibernate&spring等等)

    FeedBack:
    # re: Struts 中 html:options 的使用
    2008-05-07 19:03 | redleaf
    您好,這個有源碼嗎?
    沒怎么看懂  回復  更多評論
      
    # re: Struts 中 html:options 的使用 [未登錄]
    2008-07-24 16:04 | haha
    labelProperty屬性去掉就可以了,  回復  更多評論
      
    # re: Struts 中 html:options 的使用
    2009-04-01 17:56 | 打假
    去死吧,全他是抄來,且是錯的。  回復  更多評論
      
    <2007年1月>
    31123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    這個博客主要是關于java技術和開源技術,大家一起來進步了!

    常用鏈接

    留言簿(12)

    隨筆分類

    隨筆檔案

    文章分類

    收藏夾

    DotNet

    Java技術網站

    Linux VS Unix

    其他常去網站

    常光顧的BLOG

    文學類網站

    游戲類網站

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 196805
    • 排名 - 293

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 精品无码AV无码免费专区| 黄色视屏在线免费播放| 一区二区三区四区免费视频| 国产专区一va亚洲v天堂| 亚洲.国产.欧美一区二区三区| 97在线线免费观看视频在线观看 | 国产高清不卡免费在线| 亚洲欧洲日产国码久在线观看| 国产又黄又爽又大的免费视频| 亚洲级αV无码毛片久久精品| 国产裸体美女永久免费无遮挡| 亚洲熟妇av一区二区三区漫画| baoyu777永久免费视频| 亚洲无线电影官网| www视频在线观看免费| 亚洲国产精品专区| 日韩在线a视频免费播放| 日本亚洲高清乱码中文在线观看| yy6080久久亚洲精品| 最新久久免费视频| 亚洲黄色免费观看| 成人毛片免费观看视频在线| 婷婷亚洲综合五月天小说在线| 亚洲精品成人区在线观看| 中文字幕在线观看免费| 亚洲最大在线观看| 国产精品嫩草影院免费| 一级特黄aaa大片免费看| 亚洲高清免费在线观看| 女人18一级毛片免费观看| 一级特黄录像免费播放中文版| 亚洲国产日韩一区高清在线| 在线成人a毛片免费播放| www免费黄色网| 亚洲精品乱码久久久久久下载| 国产成人免费一区二区三区| 免费无码作爱视频| 亚洲人成无码网站在线观看| 亚洲色大成网站www永久一区| 日本免费网址大全在线观看| 乱人伦中文视频在线观看免费|