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

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

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

    itVincent Blog - Java Working Fun!

    技術(shù)引領(lǐng)時(shí)代!
    posts - 117, comments - 181, trackbacks - 0, articles - 12

    JSF html標(biāo)簽(2)

    Posted on 2007-04-27 14:29 itVincent 閱讀(5118) 評(píng)論(0)  編輯  收藏
       

    JSF html標(biāo)簽

    命令類標(biāo)簽包括commandButtoncommandLink

    其主要作用在于提供一個(gè)命令按鈕或鏈接,以下舉例說明:

    • commandButton

    顯示一個(gè)命令按鈕,即輸出<input> HTML標(biāo)簽,其type屬性可以設(shè)定為buttonsubmitreset,默認(rèn)是submit,按下按鈕會(huì)觸發(fā) javax.faces.event.ActionEvent,使用例子如下:
     <h:commandButton value="送出" action="#{user.verify}"/>
     

    您可以設(shè)定image屬性,指定圖片的URL,設(shè)定了image屬性的話,<input>標(biāo)簽的type屬性會(huì)被設(shè)定為image,例如:
     <h:commandButton value="#{msgs.commandText}"
                      image="images/logowiki.jpg"
                      action="#{user.verify}"/>  

     

    • commandLink

    產(chǎn)生超鏈接,會(huì)輸出<a> HTML標(biāo)簽,而href屬性會(huì)有'#',而onclick屬性會(huì)含有一段JavaScript程序,這個(gè)JavaScript的目的是按下鏈接后自動(dòng)提交窗體,具體來說其作用就像按鈕,但外觀卻是超鏈接,包括在本體部份的內(nèi)容都會(huì)成為超鏈接的一部份,一個(gè)使用的例子如下:
     <h:commandLink value="#{msgs.commandText}"
                    action="#{user.verify}"/>
     

    產(chǎn)生的HTML輸出范例如下:
    <a href="#" onclick="document.forms['_id3']['_id3:_idcl'].value='_id3:_id13'; document.forms['_id3'].submit(); return false;">Submit</a>

    如果搭配<f:param>來使用,則所設(shè)定的參數(shù)會(huì)被當(dāng)作請(qǐng)求參數(shù)一并送出,例如:
     <h:commandLink>
       <h:outputText value="welcome"/>
       <f:param name="locale" value="zh_TW"/>
     </h:commandLink>

     

     

     

     

     

    選擇類的標(biāo)簽可略分為單選標(biāo)簽與多選標(biāo)簽,依外型的不同可以分為單選鈕(Radio)、復(fù)選框(CheckBox)、列示方塊(ListBox)與選單(Menu

    以下分別先作簡單的說明:

    • <h:selectBooleanCheckbox>

    在視圖上呈現(xiàn)一個(gè)復(fù)選框,例如:

     我同意 <h:selectBooleanCheckbox value="#{user.aggree}"/>

     
    value
    所綁定的屬性必須接受與傳回boolean型態(tài)。

     

    產(chǎn)生的html代碼:

    我同意<INPUT TYPE="checkbox" />

     

    • <h:selectOneRadio><h:selectOneListbox><h: selectOneMenu>

    這三個(gè)標(biāo)簽的作用,是讓使用者從其所提供的選項(xiàng)中選擇一個(gè)項(xiàng)目,所不同的就是其外觀上的差別,例如:

     <h:selectOneRadio value="#{user.education}">
       <f:selectItem itemLabel="
    高中" itemValue="高中"/>
       <f:selectItem itemLabel="
    大學(xué)" itemValue="大學(xué)"/>
       <f:selectItem itemLabel="
    研究所以上" itemValue="研究所以上"/>
     </h:selectOneRadio><p>

     

    value所綁定的屬性可以接受字符串以外的型態(tài)或是自定義型態(tài),但記得如果是必須轉(zhuǎn)換的型態(tài)或自定義型態(tài),必須搭配 標(biāo)準(zhǔn)轉(zhuǎn)換器 自定義轉(zhuǎn)換器 來轉(zhuǎn)換為對(duì)象,<h:selectOneRadio>

    產(chǎn)生的html代碼:

     

    高中<INPUT TYPE="radio" NAME="1" value="高中"/>

    大學(xué)<INPUT TYPE="radio" NAME="1" value="大學(xué)"/>

    研究所以上<INPUT TYPE="radio" NAME="1" value="研究所以上">

     

    您也可以設(shè)定layout屬性,可設(shè)定的屬性是lineDirectionpageDirection,預(yù)設(shè)是lineDirection,也就是由左到右來排列選項(xiàng),如果設(shè)定為pageDirection,則是由上至下排列選項(xiàng),例如設(shè)定為:

     <h:selectOneRadio layout="pageDirection"
                       value="#{user.education}">
       <f:selectItem itemLabel="
    高中" itemValue="高中"/>
       <f:selectItem itemLabel="
    大學(xué)" itemValue="大學(xué)"/>
       <f:selectItem itemLabel="
    研究所以上" itemValue="研究所以上"/>
     </h:selectOneRadio><p>

     

    <h:selectOneListbox><h: selectOneMenu>的設(shè)定方法類似于<h: selectOneRadio>



     

    • <h:selectManyCheckbox><h:selectManyListbox><h: selectManyMenu>

    這三個(gè)標(biāo)簽提供用戶復(fù)選項(xiàng)目的功能,一個(gè)<h:selectManyCheckbox>例子如下:

     <h:selectManyCheckbox layout="pageDirection"
                           value="#{user.preferColors}">
         <f:selectItem itemLabel="
    " itemValue="false"/>
         <f:selectItem itemLabel="
    " itemValue="false"/>
         <f:selectItem itemLabel="
    藍(lán)" itemValue="false"/>
     </h:selectManyCheckbox><p>  

     

    value所綁定的屬性必須是數(shù)組或集合(Collection)對(duì)象,在這個(gè)例子中所使用的是boolean數(shù)組,例如:

     package onlyfun.caterpillar;

     public class UserBean {
        private boolean[] preferColors;

        public boolean[] getPreferColors() {
            return preferColors;
        }

        public void setPreferColors(boolean[] preferColors) {
            this.preferColors = preferColors;
        }

        ......
     }

     

    如果是其它型態(tài)的對(duì)象,必要時(shí)必須搭配轉(zhuǎn)換器(Converter)進(jìn)行字符串與對(duì)象之間的轉(zhuǎn)換。

    <h:selectManyListbox>的設(shè)定方法類似

     

     

    選擇類標(biāo)簽可以搭配<f:selectItem><f:selectItems>標(biāo)簽來設(shè)定選項(xiàng),例如:

     <f:selectItem itemLabel="高中"
                   itemValue="
    高中"
                   itemDescription="
    學(xué)歷"
                   itemDisabled="true"/>

     

    itemLabel
    屬性設(shè)定顯示在網(wǎng)頁上的文字,itemValue設(shè)定發(fā)送至服務(wù)器端時(shí)的值,itemDescription 設(shè)定文字描述,它只作用于一些工具程序,對(duì)HTML沒有什么影響,itemDisabled設(shè)定是否選項(xiàng)是否作用,這些屬性也都可以使用JSF Expression Language來綁定至一個(gè)值。

    <f:selectItem>
    也可以使用value來綁定一個(gè)傳回javax.faces.model.SelectItem的方法,例如:

     <f:selectItem value="#{user.sex}"/>

     

    則綁定的Bean上必須提供下面這個(gè)方法:

     ....
         public SelectItem getSex()  {
            return new SelectItem("
    ");
         }
     ....

     

    如果要一次提供多個(gè)選項(xiàng),則可以使用<f:selectItems>,它的value綁定至一個(gè)提供傳回SelectItem?的數(shù)組、集合,或者是Map對(duì)象的方法,例如:

     <h:selectOneRadio value="#{user.education}">
         <f:selectItems value="#{user.educationItems}"/>
     </h:selectOneRadio><p>

     

    這個(gè)例子中<f:selectItems>value綁定至user.educationItems,其內(nèi)容如下:

     ....
         private SelectItem[] educationItems;
       
        public SelectItem[] getEducationItems() {
            if(educationItems == null) {
                educationItems = new SelectItem[3];   
                educationItems[0] =
                      new SelectItem("
    高中", "高中");
                educationItems[1] =
                      new SelectItem("
    大學(xué)", "大學(xué)");
                educationItems[2] =
                      new SelectItem("
    研究所以上", "研究所以上");
            }
           
            return educationItems;
        }
     ....
     


    在這個(gè)例子中,SelectItem的第一個(gè)構(gòu)造參數(shù)用以設(shè)定value,而第二個(gè)參數(shù)用以設(shè)定labelSelectItem還提供有數(shù)個(gè)構(gòu)造函式,記得可以參考一下線上API文件。

    您也可以提供一個(gè)傳回Map對(duì)象的方法,Mapkey-value會(huì)分別作為選項(xiàng)的label-value,例如:

     <h:selectManyCheckbox layout="pageDirection"
                           value="#{user.preferColors}">
        <f:selectItems value="#{user.preferColorItems}"/>
     </h:selectManyCheckbox><p> 

     

    您要提供下面的程序來搭配上面這個(gè)例子:

     ....
        private Map preferColorItems;
       
        public Map getPreferColorItems() {
            if(preferColorItems == null) {
                preferColorItems = new HashMap();
                preferColorItems.put("
    ", "Red");
                preferColorItems.put("
    ", "Yellow");
                preferColorItems.put("
    藍(lán)", "Blue");
            }
           
            return preferColorItems;
        }

     


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 女人隐私秘视频黄www免费| 亚洲一级毛片免费观看| 亚洲中文字幕成人在线| 国产美女精品久久久久久久免费| 亚洲中文无码永久免费| 91网站免费观看| 67194熟妇在线永久免费观看| 99视频在线看观免费| 精品无码无人网站免费视频 | 亚洲国产香蕉碰碰人人| 国产AV无码专区亚洲精品| 亚洲bt加勒比一区二区| 亚洲国产综合专区电影在线 | 久99精品视频在线观看婷亚洲片国产一区一级在线 | 国产精品区免费视频| 久久国产精品免费视频| 一级毛片免费毛片一级毛片免费 | 一区二区视频在线免费观看| 国产在线观a免费观看| 日本一道本不卡免费| 午夜免费1000部| 香蕉视频在线观看免费国产婷婷| 国产传媒在线观看视频免费观看| 亚洲av午夜精品一区二区三区| 国产亚洲老熟女视频| 91亚洲国产成人久久精品网站| 亚洲乱码中文论理电影| 亚洲1区2区3区精华液| 一级做a毛片免费视频| 人妻免费一区二区三区最新| 日韩av无码久久精品免费| 黄页免费的网站勿入免费直接进入| 女人18特级一级毛片免费视频| 免费在线观看毛片| 亚洲AV综合色区无码另类小说 | 亚洲国产成人久久精品99| 亚洲日产韩国一二三四区| 亚洲视频在线免费播放| 亚洲最大av资源站无码av网址| 美女视频黄a视频全免费网站色 | 美女尿口扒开图片免费|