2 Replies Latest reply on Dec 5, 2010 9:28 AM by romeo_zdrite

    Rendering an image from a byte array in JSF

    romeo_zdrite

      Hey,

       

      I'm trying to render an image in a jsp page from a backing bean which has it stored as an array of bytes, and so far I haven't found any tag or method to do this (probably the answer is very easy but I can't see it - so far I've been searching for a tag that accepts the byte array as value and displays the image). I need this solution in order to display images associated with the rows of a rich:dataTable.

       

      I already tried to save them on the local disk and use h:graphicImage tag to display them but that didn't work as planned. I can see the images only if I save them in the myProj/web/.. directory, and if I do so I can see the images saved only after I restart the application (after the saving process).

       

      Thanks in advance

        • 1. Re: Rendering an image from a byte array in JSF
          romeo_zdrite

          I found a partial solution.

          I created a servlet which takes as parameter the location of the image I want to display and I call the servlet address from a h:graphicImage tag. The only problem is that the location is hardcoded atm, and I need it to be taken out from a "var" field of a rich:datatable. if anyone has a quick method to form a servlet path in a "value" field of a h:graphicImage from a field stored in a "var" item of a dataTable, please help.

           

          Thanks

          • 2. Re: Rendering an image from a byte array in JSF
            romeo_zdrite

            I found the final solution as well. I've written the h:graphicImage tag smth like

             

            <h:graphiImage value="/myServlet?location=+#{bean.location}" />

             

            The + sign concatenates my strings.