0 Replies Latest reply on Oct 1, 2008 9:47 AM by marcusdidiusfalco

    Own JSF Component Hello World

    marcusdidiusfalco

      Hello,
      I am trying to learn how to build my own components with JSF. However I cannot get the simplest example to run :-(


      Using JBoss 4.2.2.GA

      package simple;
      
      import java.io.IOException;
      
      import javax.faces.component.UIComponentBase;
      import javax.faces.component.UIOutput;
      import javax.faces.context.FacesContext;
      import javax.faces.context.ResponseWriter;
      
      public class UISimple extends UIComponentBase {
      
       @Override
       public void encodeBegin(FacesContext context) throws IOException {
      
       }
      
       @Override
       public void encodeEnd(FacesContext context) throws IOException {
       ResponseWriter responseWriter = context.getResponseWriter();
       responseWriter.startElement("h1", null);
       responseWriter.writeText("foobar", null);
       responseWriter.endElement("h1");
       responseWriter.flush();
       }
      
       @Override
       public String getFamily() {
       // TODO Auto-generated method stub
       return null;
       }
      
       @Override
       public void decode(FacesContext context) {
       return;
       }
      }
      


      package simple;
      
      import javax.faces.webapp.UIComponentELTag;
      
      public class SimpleTag extends UIComponentELTag {
      
       @Override
       public String getComponentType() {
       return "simple.Simple";
       }
      
       @Override
       public String getRendererType() {
       return null;
       }
      
      }


      WEB-INF/simple.tld
      <?xml version="1.0" encoding="UTF-8"?>
      <taglib 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
       http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
       version="2.1">
       <tlib-version>1.1</tlib-version>
       <short-name>spinner</short-name>
       <uri>http://corejsf.com/simple</uri>
       <tag>
       <name>simple</name>
       <tag-class>simple.SimpleTag</tag-class>
       <body-content>scriptless</body-content>
      
      
       </tag>
      </taglib>
      

      WEB-INF/faces-config.xml
      <?xml version="1.0"?>
      <faces-config 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
       http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
       version="1.2">
       <component>
       <component-type>simple.Simple</component-type>
       <component-class>simple.UISimple</component-class>
       </component>
      
      </faces-config>
      

      WEB-INF/web.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
       <display-name>OwnComponent</display-name>
       <servlet>
       <servlet-name>Faces Servlet</servlet-name>
       <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
       <load-on-startup>1</load-on-startup>
       </servlet>
      
       <servlet-mapping>
       <servlet-name>Faces Servlet</servlet-name>
       <url-pattern>*.faces</url-pattern>
       </servlet-mapping>
      
       <welcome-file-list>
       <welcome-file>index.faces</welcome-file>
       </welcome-file-list>
      </web-app>

      The Jsp:
      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
       pageEncoding="ISO-8859-1"%>
      <%@ taglib uri="http://corejsf.com/simple" prefix="s" %>
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>Simple</title>
      </head>
      <body>
       test
       <s:simple />
      </body>
      </html>
      


      Except for "test" nothing is rendered.
      What is my mistake?

      And in a related issue:
      How do I turn on debug Mode for JSF?
      I never see anything in the log files relating to JSF.

      Thanks for any help,

      Hans