2 Replies Latest reply on Jul 5, 2008 1:34 PM by ar.mohseni

    Custom jsf components with Seam

    ziphyre

      Hi,


      It's my first try on creating a custom component, and I think somethings going wrong. I'm not sure if it's more related to JSF than Seam, but since everything seems right to me on the JSF side, perhaps there's a glitch with seam.


      Basically

      <sn:spinner id="test" />

      renders itself as
      <spinner id="test" /> 

      instead of
      <span>test</span>


      I'll put right down the structure and snippets of codes, and will be very happy if anyone indicate where might be the problem:
      Thanks.


      Here is the file structure


      snodd.war:


      +WEB-INF
         -Snodd.tld
         -faces-config.xml
         +classes
            +com
               +foo
                  -SpinnerTag.java
                  -UISpinner.java
      -home.xhtml



      home.xhtml:



      <html xmlns:sn="http://foo.com/snodd" >
      ....
      <sn:spinner id="test" />





      Snodd.tld



      <?xml version="1.0" encoding="UTF-8"?>
      <taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd">
         <tlib-version>1.2</tlib-version>
         <short-name>sn</short-name>
         <uri>http://foo.com/snodd</uri>
         <tag>
            <name>spinner</name>
            <tag-class>com.foo.SpinnerTag</tag-class>
            <body-content>empty</body-content>
            ...
            ...



      faces-config.xml


      <component>
         <component-type>com.foo.Spinner</component-type>
         <component-class>com.foo.UISpinner</component-class>
      </component>



      SpinnerTag.java


      public String getComponentType() { 
         return "com.foo.Spinner"; }
      



      UISpinner.java


      public UISpinner() {
              setRendererType(null);          
      }
      
      public void encodeBegin(FacesContext context) throws IOException {
              ResponseWriter writer = context.getResponseWriter();
              String clientId = getClientId(context);
              
              encodeTestOutput(writer, clientId);
      }
      
      public void decode(FacesContext context) {
              Map<String, String>       requestMap = context.getExternalContext().getRequestParameterMap();
              String clientId = getClientId(context);
      }
      
      private void encodeTestOutput(ResponseWriter writer, String clientId) throws IOException {
              writer.startElement("span", this);
              writer.write("test");
              writer.endElement("span");
      }