Kimi's NutShell

我荒废的今日,正是昨日殒身之人祈求的明日

BlogJava 新随笔 管理
  141 Posts :: 0 Stories :: 75 Comments :: 0 Trackbacks

1.Tag类
package ticker;

import javax.faces.component.UIComponent;

import javax.faces.webapp.UIComponentTag;

public class TickerTag extends UIComponentTag {

    public void release() {

        // the super class method should be called

        super.release();

    }

    protected void setProperties(UIComponent component) {

        // the super class method should be called

        super.setProperties(component);

    }

    public String getComponentType() {

        return "ticker";
    }

    public String getRendererType() {

        // null means the component renders itself

        return "ticker.renderer";

    }

}
2.UI类
   package ticker;

import java.io.IOException;

import javax.faces.component.UIOutput;

import javax.faces.context.FacesContext;

import javax.faces.context.ResponseWriter;

public class UITicker extends UIOutput {
public UITicker(){
    setRendererType("ticker.renderer");  

}

    public void encodeBegin(FacesContext context) throws IOException {
        ResponseWriter writer = context.getResponseWriter();
        writer.write(" <link type='text/css' rel='StyleSheet' href='css/datepicker.css'/> \n" +
        "<script type='text/javascript' src='js/datepicker.js'></script> \n"+
        "<script type='text/javascript'> \n " +
                     "var d = new Date();\n" +
                     " var dp = new DatePicker(d,d);\n" +
                     "document.body.appendChild(dp.create());\n" +
                     "</script>");
    }


    public void encodeEnd(FacesContext context) throws IOException {
    }

}
3.Tld档
    <?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"

"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>

 <tlib-version>1.0</tlib-version>

 <jsp-version>1.2</jsp-version>

 <short-name>d</short-name>

 <uri>http://jsftutorials.com/</uri>


 <tag>

  <name>ticker</name>

  <tag-class>ticker.TickerTag</tag-class>

  <body-content>JSP</body-content>

</tag>

</taglib>

4.faces-config 配置
 <component>
    <component-type>ticker</component-type>
    <component-class>ticker.UITicker</component-class>
  </component>

 

 

posted on 2006-05-23 11:31 Kimi 阅读(253) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: