8 Replies Latest reply on Aug 31, 2009 8:08 PM by Arbi Sookazian

    need help with s:graphicImage

    Arbi Sookazian Master

      xhtml:


      <s:graphicImage value="#{equipmentChangeHistory.loadImage()}"/>



      backing bean:


      public byte[] loadImage(){
                
                String itemNumber = equipmentProcessing.getEquipmentProcessingListSelection().getItemNumber();
                int icomsSiteID = equipmentProcessing.getSelectedListValueForSite().getCode();
                
                List imageList = entityManager.createNativeQuery("select cast(imex.imgWebSmall as binary) "+
                                                                                        " from [corg0db32\\orgsqldw].coxReports.managed.ORG_ITEM_MASTER_EXTENSION as imex, "+
                                                                                        " EquipmentRecovery as er "+
                                                                                        " where imex.ITEM_NUMBER = er.ItemNumber "+
                                                                                        " and imex.SiteID = er.IcomsSiteID "+
                                                                                        " and er.ItemNumber = :itemNumber "+
                                                                                        " and er.IcomsSiteID = :icomsSiteID ")
                                                               .setParameter("itemNumber", itemNumber)
                                                               .setParameter("icomsSiteID", icomsSiteID)
                                                               .getResultList();
                
                if (imageList != null && imageList.size() > 0)
                     return (byte[])imageList.get(0);
                else
                     return null;
                                                
           }



      The column imex.imgWebSmall is defined as varbinary(max) in SQL SERVER 2005 db.


      We used this in a previous project (sproc DAO component):


      byte[] webSmallImage = rs.getBytes("IMGWEBSMALL");



      and it works.  Now I'm using JPA native query.


      I am getting:


      16:20:24,477 INFO  [STDOUT] Hibernate: 
          /* dynamic native SQL query */ select
              cast(imex.imgWebSmall as binary)  
          from
              [corg0db32\orgsqldw].coxReports.managed.ORG_ITEM_MASTER_EXTENSION as imex,
              EquipmentRecovery as er  
          where
              imex.ITEM_NUMBER = er.ItemNumber  
              and imex.SiteID = er.IcomsSiteID  
              and er.ItemNumber = ?  
              and er.IcomsSiteID = ? 
      16:20:26,196 INFO  [ProfilingInterceptor] *** Method class org.jboss.seam.intercept.EE5SeamInvocationContext.public byte[] com.cox.ers.session.EquipmentChangeHistoryAction.loadImage() executed in 11876ms ***
      16:20:26,211 ERROR [STDERR] Aug 28, 2009 4:20:26 PM com.sun.facelets.FaceletViewHandler handleRenderException
      SEVERE: Error Rendering View[/EquipmentProcessingHistory.xhtml]
      java.lang.ArrayIndexOutOfBoundsException: -1
           at java.util.ArrayList.get(ArrayList.java:323)
           at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:340)
           at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:431)
           at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:547)
           at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:880)
           at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:864)
           at org.jboss.seam.ui.graphicImage.Image.readImage(Image.java:457)
           at org.jboss.seam.ui.graphicImage.Image.readImage(Image.java:405)
           at org.jboss.seam.ui.graphicImage.Image.setInput(Image.java:141)
           at org.jboss.seam.ui.graphicImage.GraphicImageRendererBase.doEncodeBegin(GraphicImageRendererBase.java:31)
           at org.jboss.seam.ui.util.cdk.RendererBase.encodeBegin(RendererBase.java:79)
           at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:808)
           at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:275)
           at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
           at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:832)
           at org.ajax4jsf.renderkit.RendererBase.renderChild(RendererBase.java:277)
           at org.ajax4jsf.renderkit.RendererBase.renderChildren(RendererBase.java:258)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:220)
           at org.richfaces.renderkit.html.PanelRenderer.doEncodeChildren(PanelRenderer.java:215)
           at org.ajax4jsf.renderkit.RendererBase.encodeChildren(RendererBase.java:120)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:832)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:234)
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:239)
           at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:178)
           at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:126)
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:832)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:936)
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)
           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:109)
           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 jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:125)
           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.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           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:178)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
           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:182)
           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)



      Any idea how to resolve this?


      Also, the following xml snippet does not work in pages.xml:


       <page view-id="/EquipmentProcessingHistoty.xhtml">
               <action execute="#{equipmentChangeHistory.loadImage()}"/>
          </page>



      Any idea why not?  There is no typo, I checked.  I also tried:


       <page view-id="/EquipmentProcessingHistoty.xhtml">
               <action execute="#{equipmentChangeHistory.loadImage}"/>
          </page>



      Method is not executed also in this case when I navigate to the JSF page.


      Currently the public method above is being executed 3 times every time I navigate to the JSF page and using the following did not help that:


      @Factory(scope=ScopeType.PAGE)



      or


      @Factory(scope=ScopeType.EVENT)



      Strange stuff....