2 Replies Latest reply on Feb 17, 2006 10:19 AM by gavin.king

    Customer JSF component not worked !!

    ericmacau

      Hello,

      I create a simple JSF component to use in Seam, but it seems not work.
      And it just show nothing in the browser. When I view the HTML source, it just keep the TAG in the XHTML without rendered !

      Anything I missed to do, please teach me ???

      The following is my codes and configuration:


      The test.jar file list.

      test.jar
       |_ META-INF
       | |__ test.taglib.xml
       | |__ test.tld
       |__ test
       |_ CopyrightComponent.class
       |_ CopyrightTag.class
      



      test.taglib.xml
      <?xml version="1.0">
      <!DOCTYPE facelet-taglib PUBLIC
       "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
       "http://java.sun.com/dtd/facelet-taglib_1_0.dtd">
      
      <facelet-taglib>
       <namespace>http://test.com/jsf/tags</namespace>
       <tag>
       <tag-name>copyright</tag-name>
       <component>
       <component-type>copyright</component-type>
       </tag>
      </facelet-taglib>
      



      test.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>rs</short-name>
       <uri>http://test.com/jsf/tags</uri>
       <description>Test tags</description>
      
       <tag>
       <name>copyright</name>
       <tag-class>mo.eric.reales.web.jsf.tag.CopyrightTag</tag-class>
       <body-content>JSP</body-content>
       <attribute>
       <name>startYear</name>
       <required>true</required>
       <rtexprvalue>true</rtexprvalue>
       </attribute>
       <attribute>
       <name>name</name>
       <required>true</required>
       <rtexprvalue>true</rtexprvalue>
       </attribute>
       <attribute>
       <name>message</name>
       <required>true</required>
       <rtexprvalue>true</rtexprvalue>
       </attribute>
       </tag>
      </taglib>
      
      




      The test.xhtml
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:rs="http://test.com/jsf/tags">
      <body>
      <rs:copyright startYear="2005" name="Eric Chow" message="All right reserved."></rs:copyright>
      </body>
      </html>
      






      public class CopyrightTag extends UIComponentTag {
      
       /**
       *
       */
       public CopyrightTag() {
       super();
       // TODO Auto-generated constructor stub
       }
      
       /* (non-Javadoc)
       * @see javax.faces.webapp.UIComponentTag#getComponentType()
       */
       @Override
       public String getComponentType() {
       // TODO Auto-generated method stub
       return "copyright";
       }
      
       /* (non-Javadoc)
       * @see javax.faces.webapp.UIComponentTag#getRendererType()
       */
       @Override
       public String getRendererType() {
       // TODO Auto-generated method stub
       return null;
       }
      
       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 class CopyrightComponent extends UIOutput {
       protected int startYear;
       protected String name;
       protected String message;
      
       /**
       *
       */
       public CopyrightComponent() {
       super();
       }
      
       public void encodeBegin(FacesContext context) throws IOException {
       ResponseWriter writer = context.getResponseWriter();
       writer.startElement("div", this);
      
      
       Calendar cal = Calendar.getInstance();
       int year = cal.get(Calendar.YEAR);
       String toYear = (2006 == year) ? "" : " - " + year;
      
       writer.write("© ");
       writer.write(startYear);
       writer.write(toYear);
       writer.write(" ");
       writer.write(name);
       writer.write(" ");
       writer.write(message);
       }
      
       public void encodeEnd(FacesContext context) throws IOException {
       ResponseWriter writer = context.getResponseWriter();
       writer.endElement("div");
       }
      
       /**
       * @return Returns the message.
       */
       public String getMessage() {
       return this.message;
       }
      
       /**
       * @param message The message to set.
       */
       public void setMessage(String message) {
       this.message = message;
       }
      
       /**
       * @return Returns the name.
       */
       public String getName() {
       return this.name;
       }
      
       /**
       * @param name The name to set.
       */
       public void setName(String name) {
       this.name = name;
       }
      
       /**
       * @return Returns the startYear.
       */
       public int getStartYear() {
       return this.startYear;
       }
      
       /**
       * @param startYear The startYear to set.
       */
       public void setStartYear(int startYear) {
       this.startYear = startYear;
       }
      }