5 Replies Latest reply on Apr 17, 2008 6:04 AM by Vemula sriramsudheer

    IText + Custom component + ClassNotFoundException

    Vemula sriramsudheer Newbie
      
      package xyz.components;
      
      
      import java.io.IOException;
      
      import java.io.Serializable;
      
      
      import javax.faces.context.FacesContext;
      
      
      import org.jboss.seam.annotations.In;
      
      import org.jboss.seam.log.Log;
      
      import org.jboss.seam.pdf.ui.ITextComponent;
      
      import org.jboss.seam.pdf.ui.UIDocument;
      
      
      import com.lowagie.text.DocumentException;
      
      import com.lowagie.text.Image;
      
      import com.lowagie.text.ImgTemplate;
      
      import com.lowagie.text.pdf.BarcodeEAN;
      
      import com.lowagie.text.pdf.BaseFont;
      
      import com.lowagie.text.pdf.PdfContentByte;
      
      import com.lowagie.text.pdf.PdfTemplate;
      
      import com.lowagie.text.pdf.PdfWriter;
      
      
      public class UIPdfLabel extends ITextComponent implements Serializable{
      
      
                    
      
         // @In Log log;
      
          
      
          public UIPdfLabel() {
      
               
      
          }
      
          @Override
      
          public void createITextObject(FacesContext context) {
      
          
      
          int x=10;
      
          int y=50;
      
               
      
           final UIDocument doc = (UIDocument) findITextParent(getParent(), UIDocument.class);
      
           if (doc != null) {
      
                
      
               final PdfWriter writer = (PdfWriter) doc.getWriter();
      
               final PdfContentByte cb = writer.getDirectContent();
      
               BaseFont descriptionFont = null;
      
               BaseFont apn_wareHouseFont = null;
      
               BaseFont supplierFont = null;
      
               BaseFont sellFont = null;
      
               BaseFont typeFont = null;
      
               BaseFont barcodeFont = null;
      
                try {
      
                     descriptionFont = BaseFont.createFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      
                     apn_wareHouseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      
                     supplierFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      
                     sellFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      
                     typeFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
      
                     //barcodeFont = BaseFont.createFont("msi1.afm", BaseFont.WINANSI, BaseFont.EMBEDDED);
      
                } catch (DocumentException e1) {
      
                     
      
                     e1.printStackTrace();
      
                } catch (IOException e1) {
      
                     
      
                     e1.printStackTrace();
      
                }
      
               cb.beginText();
      
               cb.setFontAndSize(descriptionFont, 14);
      
               cb.setTextMatrix(x, y);
      
               cb.showText("Centrom Tab 600MG 60TABS");
      
               cb.endText();
      
               
      
               cb.beginText();
      
               cb.setFontAndSize(apn_wareHouseFont, 8);
      
               cb.setTextMatrix(x, y-8);
      
               cb.showText("0433769499 T");
      
               cb.endText();
      
               
      
               cb.beginText();
      
               cb.setFontAndSize(sellFont, 36);
      
               cb.setTextMatrix(x+120, y-34);
      
               cb.showText("$12.34");
      
               cb.endText();
      
                        
      
               BarcodeEAN barcodeEan = new BarcodeEAN();
      
               barcodeEan.setCode("9780201615883");
      
               barcodeEan.setCodeType(BarcodeEAN.EAN13);
      
               cb.concatCTM(1, 0, 0, 1, x, y-42);
      
               barcodeEan.placeBarcode(cb, null, null);
      
              
      
               PdfTemplate template = cb.createTemplate(x,y);
      
               /*try {
      
                    
      
                     template.addImage(image);
      
                } catch (DocumentException e1) {
      
                     // TODO Auto-generated catch block
      
                     e1.printStackTrace();
      
                }*/
      
               // Note: in a production system, exceptions should be
      
               // handled in a better way
      
               try { component = new ImgTemplate(template);
      
               }
      
               catch(Exception e) {
      
                    System.out.println("Testing PDF Label");
      
                    System.out.println(e.getMessage());
      
                    }
      
                }
      
          }
      
      
          private Image component = null;
      
      
          @Override
      
          public void handleAdd(Object arg0) {
      
              throw new RuntimeException("No children allowed");
      
          }
      
      
          @Override
      
          public void removeITextObject() {
      
           component = null;
      
          }
      
      
          /** This must return a com.lowagie.text.Element object,
      
           * or else it will throw a IllegalArgumentException("cannot add " + o) */
      
          @Override
      
          public Object getITextObject() {
      
              return component;
      
          }
      
      
           
      
           
      
      
      }
      
      
      


      facesConfig.xml:


      <?xml version="1.0" encoding="UTF-8"?>
      
      <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
      
       xmlns:xi="http://www.w3.org/2001/XInclude"
      
       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">
      
       <component>
      
        <component-type>xyz.UIPdfLabel</component-type>
      
        <component-class>xyz.UIPdfLabel</component-class>
      
       </component>
      
       <application>
      
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
      
        <locale-config>
      
         <default-locale>en</default-locale>
      
         <supported-locale>bg</supported-locale>
      
         <supported-locale>de</supported-locale>
      
         <supported-locale>en</supported-locale>
      
         <supported-locale>fr</supported-locale>
      
         <supported-locale>tr</supported-locale>
      
        </locale-config>
      
       </application>
      
      </faces-config>



      and taglib.xml is




      <?xml version="1.0"?>
      
      <!DOCTYPE facelet-taglib PUBLIC
      
         "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"
      
         "facelet-taglib_1_0.dtd">   
      
      <facelet-taglib>
      
          <namespace>http://xyz/products/dvComponents</namespace>
      
      
           <tag>
      
              <tag-name>pdfLabel</tag-name>
      
              <component>
      
                  <component-type>xyz.UIPdfLabel</component-type>
      
              </component>
      
          </tag>
      
      
      </facelet-taglib>




      and I am Getting CLassNotFound Exception could any one help what i am missing


      Thank You In Advance



      <p:document type="PDF" pageSize="A4" title="barcode" margins="1 1 1 1"
      
                          xmlns="http://www.w3.org/1999/xhtml"
      
                      xmlns:s="http://jboss.com/products/seam/taglib"
      
                      xmlns:ui="http://java.sun.com/jsf/facelets"
      
                      xmlns:f="http://java.sun.com/jsf/core"
      
                      xmlns:h="http://java.sun.com/jsf/html"
      
                      xmlns:rich="http://richfaces.org/rich"
      
                      xmlns:dvComponent="http://xyz/products/dvComponents"
      
                      xmlns:p="http://jboss.com/products/seam/pdf"
      
                      template="layout/shelfTemplate.xhtml">           
      
               <dvComponent:pdfLabel> </dvComponent:pdfLabel>
      
      </p:document>
      
      


        • 1. Re: IText + Custom component + ClassNotFoundException
          Nicklas Karlsson Master

          If somebody can help you without information on which class is not found, I'd be amazed.


          Seam version, deployment type (ear or war), seam & appserver versions and generation type (seam-gen / jboss tools) might also help.

          • 2. Re: IText + Custom component + ClassNotFoundException
            Vemula sriramsudheer Newbie

            Hi Nicklas, Sorry for that incomplete question here is the stackTrace:



            17:08:06,027 WARN  [application] JSF1004: Cannot instantiate component of type xyz.components.UIPdfLabel
            17:08:06,027 ERROR [STDERR] Apr 16, 2008 5:08:06 PM com.sun.facelets.FaceletViewHandler handleRenderException
            SEVERE: Error Rendering View[/shelfLabels.xhtml]
            javax.faces.FacesException: javax.faces.FacesException: xyz.components.UIPdfLabel
                 at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:545)
                 at org.jboss.seam.jsf.SeamApplication.createComponent(SeamApplication.java:91)
                 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.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
                 at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
                 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:310)
                 at com.sun.facelets.impl.DefaultFaceletContext.includeDefinition(DefaultFaceletContext.java:280)
                 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.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:144)
                 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.jboss.seam.jsf.SeamViewHandler.renderView(SeamViewHandler.java:87)
                 at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
                 at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:216)
                 at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
                 at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
                 at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
                 at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                 at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
                 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                 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.MultipartFilter.doFilter(MultipartFilter.java:85)
                 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:141)
                 at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
                 at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
                 at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                 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:230)
                 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
                 at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
                 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                 at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
                 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
                 at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
                 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
                 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
                 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
                 at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                 at java.lang.Thread.run(Thread.java:595)
            Caused by: javax.faces.FacesException: xyz.components.UIPdfLabel
                 at com.sun.faces.application.ApplicationImpl.newThing(ApplicationImpl.java:1007)
                 at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:539)
                 ... 69 more
            Caused by: java.lang.ClassNotFoundException: xyz.components.UIPdfLabel
                 at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                 at java.security.AccessController.doPrivileged(Native Method)
                 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                 at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
                 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
                 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
                 at java.lang.Class.forName0(Native Method)
                 at java.lang.Class.forName(Class.java:242)
                 at com.sun.faces.util.Util.loadClass(Util.java:227)
                 at com.sun.faces.application.ApplicationImpl.newThing(ApplicationImpl.java:1003)
                 ... 70 more
            


            • 3. Re: IText + Custom component + ClassNotFoundException
              Nicklas Karlsson Master

              war or ear? where is your component packaged and placed?

              • 5. Re: IText + Custom component + ClassNotFoundException
                Vemula sriramsudheer Newbie

                Please Let me know if i am still missing some thing more