1 Reply Latest reply on May 8, 2010 7:19 PM by Christoph Hirte

    Custom UIComponent not working. Cannot instantiate component

    Christoph Hirte Newbie

      Hey guys,

       

      I've got a serious problem a custom UIComponent that I developed and tried to use in my application.

      First of all here is some code and configuration stuff that makes up my component:

       

      1. the UIComponent class:

      ====================================

       

      package de.bobdesign.bobnet.custom;
      import java.io.IOException;
      import javax.faces.component.UIComponentBase;
      import javax.faces.context.FacesContext;
      import javax.faces.context.ResponseWriter;
      public class CockpitUIComponent extends UIComponentBase {
      public CockpitUIComponent () {
      setRendererType(null);
      }
      @Override
      public void encodeBegin(FacesContext ctx) throws IOException {
      super.encodeBegin(ctx);
      ResponseWriter writer = ctx.getResponseWriter();
      String clientId = getClientId(ctx);
      encodeTable(writer, clientId);
      }
      @Override
      public String getFamily() {
      // TODO Auto-generated method stub
      return null;
      }
      private void encodeTable(ResponseWriter out, String clientId) {
      try {
      out.startElement("p",null);
      out.writeAttribute("name", clientId, null);
      out.writeText("Hello World", null);
      out.endElement("p");
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
      }

       

      2. The Facelets - taglib.xml (real name: cockpit.taglib.xml which resides in the META-INF - dir)

      ====================================

       

      <?xml version="1.0" encoding="UTF-8"?>

      <!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://wirtschaftsinformatiker.name/cockpit</namespace>

          <tag>

              <tag-name>cockpit</tag-name>

              <component>

                  <component-type>de.bobdesign.bobnet.custom.CockpitUIComponent</component-type>

              </component>

          </tag>

      </facelet-taglib>

       

       

       

      3. TLD - (real name: cockpit.tld which resides in the META-INF - dir)

      ====================================

      <?xml version="1.0" encoding="UTF-8"?>

      <taglib

      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"

         xmlns="http://java.sun.com/xml/ns/javaee"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         version="2.1">

       

      <tlib-version>1.1</tlib-version>

      <short-name>cockpit</short-name>

      <uri>http://wirtschaftsinformatiker.name/cockpit</uri>

       

      <tag>

      <name>cockpit</name>

      <tag-class>de.bobdesign.bobnet.custom.CockpitTag</tag-class>

      <body-content>empty</body-content>

      </tag>

      </taglib>

       

       

       

      4. web.xml - context parameter

      ====================================

      <context-param>

        <param-name>facelets.LIBRARIES</param-name>

        <param-value>/META-INF/cockpit.taglib.xml</param-value>

      </context-param>

       

       

      5. faces-config.xml - component definition

      ====================================

      <component>

        <component-type>de.bobdesign.bobnet.custom.Cockpit</component-type>

        <component-class>de.bobdesign.bobnet.custom.CockpitUIComponent</component-class>

      </component>

       

       

      6. home.xhtml - which should display my component

      ====================================

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"

          xmlns:ch="http://wirtschaftsinformatiker.name/cockpit"

          xmlns:ui="http://java.sun.com/jsf/facelets"

          template="../template/template.xhtml">

       

          <ui:define name="body">

          <ch:cockpit/>

          </ui:define>

      </ui:composition>

       

       

      All this leads to the following error in my server.log:

      ====================================

      2010-05-08 02:03:12,671 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-192.168.2.100-8080-6) JSF1004: Cannot instantiate component of type de.bobdesign.bobnet.custom.CockpitUIComponent

      2010-05-08 02:03:12,671 ERROR [facelets.viewhandler] (http-192.168.2.100-8080-6) Error Rendering View[/co/home.xhtml]

      javax.faces.FacesException: Expression Error: Object: de.bobdesign.bobnet.custom.CockpitUIComponent wurde nicht gefunden.

      at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:570)

      at org.jboss.seam.jsf.SeamApplication.createComponent(SeamApplication.java:92)

      at com.sun.facelets.tag.jsf.ComponentHandler.createComponent(ComponentHandler.java:243)

      at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:139)

      at com.sun.facelets.tag.ui.DefineHandler.applyDefinition(DefineHandler.java:64)

      at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:131)

      at com.sun.facelets.impl.DefaultFaceletContext$TemplateManager.apply(DefaultFaceletContext.java:337)

      at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:307)

      at com.sun.facelets.tag.ui.InsertHandler.apply(InsertHandler.java:68)

      at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)

      at com.sun.facelets.tag.jsf.core.ViewHandler.apply(ViewHandler.java:109)

      at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)

      at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)

      at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)

      at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)

      at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)

      at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:273)

      at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:140)

      at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:113)

      at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)

      at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)

      at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)

      at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)

      at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)

      at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)

      at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)

      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)

      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)

      at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)

      at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

      at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:390)

      at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:517)

      at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)

      at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:73)

      at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)

      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)

      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)

      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)

      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)

      at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)

      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)

      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)

      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)

      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

      at java.lang.Thread.run(Thread.java:619)

       

       

      I mess around for over a day now and I've completly no idea where the problem could be.

      Any ideas what this might cause? Thanx in advance!!!

       

      Regards CH

        • 1. Re: Custom UIComponent not working. Cannot instantiate component
          Christoph Hirte Newbie

          Fixed it!

          The value for each of the <component-type> tags in faces-config.xml and the cockpit.taglib.xml were not the same.

           

          I changed the following (red things)

           

          faces-config.xml (excerpt)

          ===========================

          <component>

            <component-type>de.bobdesign.bobnet.custom.Cockpit</component-type>

            <component-class>de.bobdesign.bobnet.custom.CockpitUIComponent</component-class>

          </component>

           

           

          cockpit.taglib.xml (excerpt)

          ===========================

          <facelet-taglib>

              <namespace>http://wirtschaftsinformatiker.name/cockpit</namespace>

              <tag>

                  <tag-name>cockpit</tag-name>

                  <component>

                      <component-type>de.bobdesign.bobnet.custom.Cockpit</component-type>

                  </component>

              </tag>

          </facelet-taglib>

           

           

           

          Now it works.

          Regards CH