<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)航:
     
    主站蜘蛛池模板: 久久亚洲国产成人影院网站 | 亚洲一区AV无码少妇电影| a级毛片视频免费观看| 亚洲精品国产自在久久| 日本一区二区三区免费高清在线 | 香蕉97超级碰碰碰免费公| 777亚洲精品乱码久久久久久 | 亚洲精品乱码久久久久久按摩| 91在线免费观看| 国产中文在线亚洲精品官网| 中文字幕免费在线观看动作大片| 一本久久a久久精品亚洲| www.xxxx.com日本免费| 国产亚洲精品精华液| 久久国产免费一区二区三区| 亚洲视频免费观看| 成人爽A毛片免费看| 妇女自拍偷自拍亚洲精品| 亚洲情侣偷拍精品| 一个人免费视频在线观看www | 国产亚洲精品xxx| 4虎1515hh永久免费| 亚洲综合激情五月丁香六月| 国产成人精品123区免费视频| 日本高清免费中文在线看| 亚洲狠狠婷婷综合久久久久| 四虎在线最新永久免费| 亚洲另类自拍丝袜第五页| ZZIJZZIJ亚洲日本少妇JIZJIZ| 亚洲精品免费在线观看| 亚洲午夜一区二区三区| 一本久久综合亚洲鲁鲁五月天| a毛片全部播放免费视频完整18| 亚洲欧洲日产韩国在线| 国产乱子伦精品免费无码专区 | yy一级毛片免费视频| 久久精品亚洲综合专区| 在线中文高清资源免费观看| 中文字幕不卡高清免费| 亚洲午夜国产精品| 国产精品亚洲w码日韩中文|