0

after googling the whole day and almost going crazy, I just gave up and now trying to find out if someone can help me out with this issue.

Well, I'm trying to show an image inside p:dataTable with p:graphicImage, but the image looks like "broken" as you can see in the pic below:

enter image description here
I googled A LOT and found many people, including BaluscC saying the same thing: Getting the image as StreamedContent Object, but with me it doesn't work and the weird thing is that there's no error showing on my console. Here's my code:

On my bean "Place" getting the blob image (byte[]) and transforming to StreamedContent

public StreamedContent getImageStreamContent() {

        if(image != null){
            InputStream is = new ByteArrayInputStream(image);
            imageStreamContent = new DefaultStreamedContent (is, "image/png");
            return imageStreamContent;
        }else{
            return null;
        }
    }


Here's my dependencies on maven:

<!-- Regarding to upload image -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.1</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
        </dependency>


Here's my web.xml

 <filter>
       <filter-name>PrimeFaces FileUpload Filter</filter-name>
       <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
   </filter>
   <filter-mapping>
       <filter-name>PrimeFaces FileUpload Filter</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
   </filter-mapping>


And here's my datatable:

 <p:column headerText="Photo"  width="80">
       <p:graphicImage value="#{place.imageStreamContent}" />
 </p:column> 


Anyone would know what I'm doing wrong?

Cheers!

Rafael Paz
  • 437
  • 6
  • 17
  • Unlike text, images are not inline in HTML, when a response to a request is returned to a client. They are rather requested separately (by sending a new HTTP request thus, involving two requests to download an image - the first one to retrieve HTML contents and the other to download the file as mentioned in ``. This is how HTML works). http://stackoverflow.com/q/8207325/1391249, http://stackoverflow.com/q/10073905/1391249 – Tiny Feb 20 '16 at 12:15
  • Thank you A LOT @Tiny. That example worked out for me! – Rafael Paz Feb 21 '16 at 01:20

1 Answers1

-2

You can use Img tag of plain HTML Where path of image would be url based like

http://localhost:8080/test/images/login.png

It is working for me so i hope it will work you defnetly

Ravi Tyagi
  • 119
  • 2
  • 5