<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

    該標(biāo)簽生成一個(gè)select元素。multiple屬性決定是否為多選。如果指定了multiple="true"則為多選,此時(shí)對(duì)應(yīng)的屬性應(yīng)該是一個(gè)數(shù)組。否則,此時(shí)對(duì)應(yīng)的屬性應(yīng)該是標(biāo)量。

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

    ??? 1)html:option

    ???? 該標(biāo)簽生成一個(gè)HTML的option元素。該標(biāo)簽必須嵌在html:select標(biāo)簽中。它的顯示文本來(lái)自其標(biāo)簽體,也可以來(lái)自于資源文件。

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

    ???? <html:option value="blue">藍(lán)色</html:option>

    ?? 2)html:options

    ???? 該標(biāo)簽生成多個(gè)HTML的option元素。該標(biāo)簽必須嵌在html:select標(biāo)簽中。

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

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

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

    </html:select>

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

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

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

    </html:select>

    ??? 3)html:optionsCollection標(biāo)簽

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

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

    ?? 4)實(shí)現(xiàn)舉例

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

    ?? 沒(méi)有提出常用jsp+ActionForm這樣形式的最直接的總結(jié),現(xiàn)從中總結(jié)如下,分兩種情況:數(shù)組

    和Collection。
      
      需求,要達(dá)到:
      <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>
      
      要實(shí)現(xiàn)上述效果,需要兩步:
      第一:設(shè)置ActionForm,
      也分兩小步:第一小步必須在ActionForm中,有一句
      private Collection beanCollection;? //Collection 可以用List或者Vector
      public Collection getBeanCollection();
      Collection beanCollection要確保是一個(gè)實(shí)現(xiàn),如ArrayList,
    ?? 如果不是則會(huì)報(bào)No collection found的錯(cuò)誤,Struts的最大不方便就是一旦出問(wèn)題,

    ?? 定位很難,不知道什么地方使用錯(cuò)誤,或忘記設(shè)置什么了,不過(guò)可以查看tomcat Log的。
      
      因?yàn)榍懊嫘枨笾衞ption的value值和label值不一樣,那么在beanCollection中保存的

    就是一個(gè)value和label組成的對(duì)象,名為L(zhǎng)abelvalueBean,在LabelvalueBean中有兩個(gè)屬性value和label,
      
      在程序某個(gè)地方要為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中寫(xiě)入tang lib語(yǔ)句如下:
      
      <html:select property="beanCollectionSelect" size="10" multiple="true">
          <html:optionsCollection name="testbean" property="beanCollection"/>  
       </html:select>
      
      其中testbean是ActionForm的名稱。
      
      以上是html:options的Collection解決方案,如果option值很少,簡(jiǎn)單地可以實(shí)現(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中:
      //下面這個(gè)我使用時(shí),出錯(cuò),總是提示找布道labels,不知什么原因?
      <html:select property="selected" >     
      <html:options name="testbean" property="values" labelProperty="labels"/> 
      </html:select>
    總結(jié): 經(jīng)過(guò)這段時(shí)間的開(kāi)發(fā)和學(xué)習(xí),自我感覺(jué)struts還是不錯(cuò)的,雖然一開(kāi)始的時(shí)候有點(diǎn)麻煩,

    不過(guò)其實(shí)Java的配置也是有點(diǎn)麻煩的,不過(guò)用了這么長(zhǎng)時(shí)間的Java,現(xiàn)在覺(jué)得Java挺好的!

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

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

    這個(gè)博客主要是關(guān)于java技術(shù)和開(kāi)源技術(shù),大家一起來(lái)進(jìn)步了!

    常用鏈接

    留言簿(12)

    隨筆分類

    隨筆檔案

    文章分類

    收藏夾

    DotNet

    Java技術(shù)網(wǎng)站

    Linux VS Unix

    其他常去網(wǎng)站

    常光顧的BLOG

    文學(xué)類網(wǎng)站

    游戲類網(wǎng)站

    最新隨筆

    搜索

    •  

    積分與排名

    • 積分 - 196749
    • 排名 - 293

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 免费夜色污私人影院网站电影| 日本无卡码免费一区二区三区| 亚洲精品久久无码| 久久久久亚洲AV无码永不| 免费一级毛片在播放视频| 免费在线观看的网站| 成人精品一区二区三区不卡免费看| 亚洲国产免费综合| www.av在线免费观看| 一区二区免费电影| 中美日韩在线网免费毛片视频| 一级毛片在线播放免费| a级毛片免费观看在线| 成在人线av无码免费高潮水| 99视频在线免费观看| 日韩精品免费视频| 伊人久久免费视频| 91福利视频免费观看| 91精品成人免费国产片| 嫖丰满老熟妇AAAA片免费看| 一二三四影视在线看片免费 | 中文字幕免费观看| 亚洲啪啪免费视频| 大学生一级毛片免费看| 女人被弄到高潮的免费视频| 国产国产人免费视频成69大陆| 亚洲av无码不卡私人影院| 亚洲精品无码久久久久| 99亚洲精品高清一二区| 国产成人精品日本亚洲直接| 亚洲精品色在线网站| 高清永久免费观看| 久久国产免费观看精品3| 老司机在线免费视频| 国产18禁黄网站免费观看| 国产亚洲精品高清在线| 亚洲综合激情六月婷婷在线观看| 亚洲人成色77777在线观看| 免费VA在线观看无码| 久久一区二区免费播放| 国产大片91精品免费观看不卡|