9 Replies Latest reply on Nov 25, 2014 1:48 AM by cathy ben

    p:image is not working for me

    Manish Prajapati Newbie
      Hi all,

      i want to place an image inside the pdf document for what i have written following xhtml code :

      <p:document xmlns:p="http://jboss.com/products/seam/pdf" >
           <p:image alignment="left" wrap="true" value="/test/test1/images/headlogo.gif" />                                                    
                  <p:font size="24">
                   <p:paragraph spacingAfter="50">Fax Cover Page</p:paragraph>
               </p:font>       
             <p:barCode type="code128"
                 barHeight="80"
                 textSize="20"
                 code="(10)45566(17)040301"
                 codeType="code128"
                 altText="My BarCode" />                                                       </p:document>

      But i am getting following exception:

      java.lang.IllegalArgumentException: Image pointed to must exist (input stream must not be null)
           at org.jboss.seam.ui.graphicImage.Image.readImage(Image.java:446)
           at org.jboss.seam.ui.graphicImage.Image.readImage(Image.java:394)
           at org.jboss.seam.ui.graphicImage.Image.setInput(Image.java:141)
           at org.jboss.seam.pdf.ui.UIImage.createITextObject(UIImage.java:148)
           at org.jboss.seam.pdf.ui.ITextComponent.encodeBegin(ITextComponent.java:213)
           at org.jboss.seam.pdf.ui.ITextComponent.encode(ITextComponent.java:283)
           at org.jboss.seam.pdf.ui.ITextComponent.encodeChildren(ITextComponent.java:256)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           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 com.test.seam.infrastructure.BaseUrlFilter.doFilter(BaseUrlFilter.java:30)
           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:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           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: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:828)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)

      I have also tried with resource attribute of p:image as following (  <p:image alignment="left" wrap="true" resource="/test/test1/images/headlogo.gif" />  )but in that case i am getting following exception:

      java.lang.NullPointerException
           at java.io.ByteArrayInputStream.<init>(ByteArrayInputStream.java:89)
           at com.lowagie.text.Image.getInstance(Unknown Source)
           at org.jboss.seam.pdf.ui.UIImage.createITextObject(UIImage.java:161)
           at org.jboss.seam.pdf.ui.ITextComponent.encodeBegin(ITextComponent.java:213)
           at org.jboss.seam.pdf.ui.ITextComponent.encode(ITextComponent.java:283)
           at org.jboss.seam.pdf.ui.ITextComponent.encodeChildren(ITextComponent.java:256)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
           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 com.test.seam.infrastructure.BaseUrlFilter.doFilter(BaseUrlFilter.java:30)
           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:58)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           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: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:828)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
           at java.lang.Thread.run(Thread.java:619)


         
        • 1. Re: p:image is not working for me
          Manish Prajapati Newbie

          I can't figure out where is the problem.
          Please any body can help me to resolve this problem.


          Help will be appreciable.


          Thanks in advace.


          regards,
          Manish

          • 2. Re: p:image is not working for me
            Robert Morse Apprentice

            It can't find your image headlogo.gif.  Looks like you might be referencing some external file?   A simple fix to get you going might be to place the image file in the same location as the xhtml file, then you can determine where it really needs to be.  A better approach might be to load the image in your seam component, and then reference the byte array in the p:image component. 

            • 3. Re: p:image is not working for me
              Tom ONeill Newbie
              How do you go about using a byte array? I tried the following:

              <p:image value="#{arInvoiceBB.bytes}"/>

              And my backing bean has:


              public byte[] getBytes() throws AluaException, MalformedURLException, FileNotFoundException, IOException {

                      File logoFile = new File(imageLocation + LogoScreenBB.LOGO_FILE_NAME);
                      InputStream is = new FileInputStream(logoFile);

                      // Get the size of the file
                      long length = logoFile.length();
                      log.info("length of file: " + length);

                      if (length > Integer.MAX_VALUE) {
                          log.warn("file too big!");
                      }

                      // Create the byte array to hold the data
                      byte[] bytes = new byte[(int)length];

                      // Read in the bytes
                      int offset = 0;
                      int numRead = 0;
                      while (offset < bytes.length
                             && (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
                          offset += numRead;
                      }

                      // Ensure all the bytes have been read in
                      if (offset < bytes.length) {
                          throw new IOException("Could not completely read file "+logoFile.getName());
                      }

                      // Close the input stream and return bytes
                      is.close();
                      log.info("returning byte array");
                      return bytes;
                  }

              I end up with a null pointer though.

              03 Jun 2009 14:23:47,798 INFO   [action.com.paddockPro.backingBean.ArInvoiceBB] [1033] - length of file: 86454

              03 Jun 2009 14:23:47,798 INFO   [action.com.paddockPro.backingBean.ArInvoiceBB] [1057] - returning byte array

              03 Jun 2009 14:23:47,798 ERROR  [facelets.viewhandler] [86] - Error Rendering View[/secure/accountsReceivable/pdfInvoice.xhtml]

              java.lang.NullPointerException

                   at org.jboss.seam.ui.graphicImage.Image.getImage(Image.java:154)

                   at org.jboss.seam.pdf.ui.UIImage.createITextObject(UIImage.java:160)

                   at org.jboss.seam.pdf.ui.ITextComponent.encodeBegin(ITextComponent.java:213)


              Any advice? We are trying to display a logo that we are allowing our users to upload to our file system.


              • 4. Re: p:image is not working for me
                Tom ONeill Newbie
                Ok, got it working. Turns out that p:image wants a ByteARrayInputStream, not a byte[]. So I added these two methods to my backing bean:

                public ByteArrayInputStream getLastTry() throws AluaException, MalformedURLException, IOException, FileNotFoundException
                     {
                         log.info("In getLastTry");
                         return getAwtImage(getBytes());
                     }

                     public ByteArrayInputStream getAwtImage(byte[] data) {
                        log.info("In getAwtImage");
                        ByteArrayInputStream inStream = new ByteArrayInputStream(data);
                        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
                        try {
                            BufferedImage image = ImageIO.read(inStream);
                            ImageIO.write(image, "jpeg", outStream);
                            log.info("Just used ImageIO to write to the outstream");
                            outStream.close();
                        } catch (IOException e) {

                            e.printStackTrace();
                        }
                        return new ByteArrayInputStream(outStream.toByteArray());
                     }


                And my xhtml has:  <p:image value="#{arInvoiceBB.lastTry}"/>
                • 5. Re: p:image is not working for me
                  Robert Morse Apprentice

                  Returning byte[] works for me in Seam 2.1.2.CR2

                  • 6. Re: p:image is not working for me
                    Tom ONeill Newbie

                    Interesting. I'm on 2.1.1, but I don't see anything in the 2.1.2 release notes that implies this has changed. I won't rule out user error on my part.

                    • 7. Re: p:image is not working for me
                      Alessandro Behling Newbie

                      Hi,


                      I ran into what seems to be very closely related to the issue discussed here. I have PDF generation going on, and I am trying to insert a image into a cell within a table. I'm using a rather old version of seam (1.2.1) -- no much room to move on to a new version at this point, old app, stable, and it works --


                      I have already tried all the possible combinations I could think of, including the above with a slightly different variation, instead of a ByArrayInputStream I am passing a Image (awtImage) to the p:image component, alternatively I have also attempted loading the image from the hard drive, but that also didn't have any effect


                      the report I generate uses a log at the top, and that works just fine, I seem to be stuck 'only' with the scenario where I try to add the image into a cell / table


                      if anyone has had any experience with this, it would be of great help


                      thank you
                      a

                      • 8. Re: Re: p:image is not working for me
                        arron lee Newbie

                        Hi, mom image.

                        I agree with you that using another java code 128 barcode generatior whose way of processing is simple and fast can make all the process much more convenient to operate. And I am also testing baout the related progarmmes recently. W e can communicate about it later. Good luck.

                         

                         

                         

                        Best regards,

                        Arron

                        • 9. Re: p:image is not working for me
                          cathy ben Newbie

                          arron lee wrote:

                           

                          Hi, mom image.

                          I agree with you that using another java code 128 barcode generator whose way of processing is simple and fast can make all the process much more convenient to operate. And I am also testing baout the related progarmmes recently. W e can communicate about it later. Good luck.

                           

                           

                           

                          Best regards,

                          Arron

                          Thank you so much, I tried to search the resolutions on google, but most are useless. Your suggestion is quite helpful, I use it on my work, my images works correctly.