<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 非洲小白臉 閱讀(232) 評論(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

    具體程序參看示例程序。

     

    主站蜘蛛池模板: 免费观看激色视频网站(性色)| 亚洲成人福利在线观看| 羞羞漫画在线成人漫画阅读免费| 免免费国产AAAAA片| 亚洲高清日韩精品第一区| 无码午夜成人1000部免费视频| 亚洲中文久久精品无码| 成年女人A毛片免费视频| 中国亚洲女人69内射少妇| 精品无码一级毛片免费视频观看| 久久影院亚洲一区| 久久久WWW成人免费精品| 亚洲国产精品成人精品无码区在线| 好男人资源在线WWW免费| 亚洲AV无码一区二区乱孑伦AS| 久久久久久影院久久久久免费精品国产小说 | 日韩免费观看一区| 久久亚洲国产视频| 永久在线免费观看| 久久夜色精品国产噜噜亚洲a| 成人激情免费视频| 老妇激情毛片免费| 国产AV无码专区亚洲精品| 99爱免费观看视频在线| 亚洲一区在线视频观看| 国产小视频在线免费| 精品国产亚洲一区二区三区在线观看 | 国产乱子伦精品免费视频| 亚洲精品制服丝袜四区| 16女性下面无遮挡免费| 日本亚洲色大成网站www久久| 免费不卡中文字幕在线| 国产99视频精品免费专区| 亚洲免费网站在线观看| 国产片免费在线观看| 中国国语毛片免费观看视频| 亚洲精品成人久久| 日韩亚洲精品福利| 一本色道久久88综合亚洲精品高清| AAAAA级少妇高潮大片免费看| 亚洲黄色在线视频|