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

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

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

    爪哇一角

    共同探討STRUTS#HIBERNATE#SPRING#EJB等技術
    posts - 3, comments - 6, trackbacks - 0, articles - 99
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    十一 自定義組件標簽

    Posted on 2009-01-20 14:50 非洲小白臉 閱讀(227) 評論(0)  編輯  收藏 所屬分類: JSF

    完成了UIComponent的定制后,下面就需要自定義一個Tag來與之對應。自定義Tag的目的在于設定UIComponent的屬性,取得Renderer的值等。

    自定義Tag需要繼承UIComponentTag

    package test;

    import javax.faces.application.Application;

    import javax.faces.component.UIComponent;

    import javax.faces.context.FacesContext;

    import javax.faces.el.ValueBinding;

    import javax.faces.webapp.UIComponentTag;

    繼承了UIComponentTag

     
    public class TextWithCmdTag extends UIComponentTag {

        private String size;

        private String value;

    綁定到自定義的Component組件。

     
        public String getComponentType() {

            return "test.TextWithCmd";

        }

    綁定到Renderer。這里沒有設定,因為這個組件沒有用Renderer編解碼,而是Component自己實現的。

     
        public String getRendererType() {

            return null;

        }

        public void setProperties(UIComponent component) {

            super.setProperties(component);

          

            setStringProperty(component, "size", size);

            setStringProperty(component, "value", value);

        }

        private void setStringProperty(UIComponent component,

                           String attrName, String attrValue) {

            if(attrValue == null)

                return;

    設置Tag的值綁定到Component上。這樣,Component取值的時候,如果元件屬性設定值找不到,就會從綁定值中去尋找。

     
            if(isValueReference(attrValue)) {

                FacesContext context =

                             FacesContext.getCurrentInstance();

                Application application =

                             context.getApplication();

                ValueBinding binding =

                       application.createValueBinding(attrValue);

                component.setValueBinding(attrName, binding);

            }

            else {

                component.getAttributes().

                              put(attrName, attrValue);

            }

        }

        public void release() {

            super.release();

            size = null;

            value = null;

        }

        public String getSize() {

            return size;

        }

        public void setSize(String size) {

            this.size = size;

        }

        public String getValue() {

            return value;

        }

        public void setValue(String value) {

            this.value = value;

        }

     }

    ▲綁定到Tag上的Conponent組件用的是faces-config.xml中定義的別名,所以我們隨時可以替換掉對于的Component而不改變Tag代碼。

    自定義Tag需要在Tld中聲明:

    <tag>

         <name>textcmd</name>

         <tag-class>test.TextWithCmdTag</tag-class>

         <body-content>empty</body-content>

         <attribute>

            <name>size</name>

         </attribute>

         <attribute>

            <name>value</name>

            <required>true</required>

         </attribute>

     </tag>

    具體程序參看示例程序。

     

    新建一個JSP和一個綁定好的javaBean,就可以看到運行結果了。

    對這類jspBean的建立,前面已經有很多例子了,這里就不再說了。

    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>

    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

    <%@ taglib uri="/WEB-INF/textcmd.tld" prefix="oc"%>

    <html>

    <link href="../../styles.css" rel="stylesheet" type="text/css" />

    <head>

    <title></title>

    </head>

    <body>

    <f:view>

           <h:form>

         Input data: <oc:textcmd size="10" value="#{componentTestBean.data}" />

           </h:form>

           <h:outputText value="#{componentTestBean.data}" />

    </f:view>

    </body>

    </html>

    運行地址:http://localhost:8080/jsfTest/pages/componentTest.faces

    具體程序參看示例程序。

     

    主站蜘蛛池模板: 亚洲精品在线免费观看视频 | 91在线手机精品免费观看| 四虎在线播放免费永久视频 | va天堂va亚洲va影视中文字幕| 99在线免费观看| 亚洲韩国精品无码一区二区三区| 国产黄在线观看免费观看不卡| 国产精品亚洲mnbav网站 | 亚洲女女女同性video| 日本亚洲免费无线码| 亚洲中文字幕无码一去台湾 | 相泽南亚洲一区二区在线播放| 日韩中文字幕免费| 色视频在线观看免费| 久久久久亚洲爆乳少妇无| 国产成人免费ā片在线观看老同学| 国产精品国产亚洲精品看不卡| 免费国产污网站在线观看15| 亚洲婷婷综合色高清在线| 九九九精品成人免费视频| 亚洲AV无码成人精品区日韩| 丝袜熟女国偷自产中文字幕亚洲| 拍拍拍无挡免费视频网站| 亚洲AV无码精品色午夜果冻不卡| 91精品国产免费网站| 亚洲日韩精品国产一区二区三区 | 久久精品国产大片免费观看| 亚洲色成人网一二三区| 免费无码又爽又高潮视频| 免费无码一区二区| 亚洲Aⅴ无码专区在线观看q| 成人毛片免费观看视频大全| 一级毛片免费在线播放| 亚洲AV第一页国产精品| 人妻视频一区二区三区免费| 一边摸一边爽一边叫床免费视频| 中文字幕亚洲综合久久2| 精品国产免费观看| 在线涩涩免费观看国产精品| 丁香婷婷亚洲六月综合色| 国产精品亚洲综合专区片高清久久久|