DefaultStreamedContent problem

UI Components for JSF
Post Reply
saprobionte
Posts: 80
Joined: 20 Jun 2011, 15:46

25 Jul 2011, 15:08

Hi all,

I'm trying to display an image in my web page, this way :

Code: Select all

<p:graphicImage height="200px" width="200px" value="#{tableBean.image}"/>  
In my bean, if I use image as a string, it works :

Code: Select all

private String image = "/images/test.jpg";
But I want to use it as a StreamedContent, because I need to convert my image before I display it. So I do this :

Code: Select all

InputStream test = new FileInputStream("C:/test.jpg");
            image = new DefaultStreamedContent(test, "image/jpeg");
In that code, I do not convert my test.jpg file, but it is not correctly rendered (i got the little red cross). What am I doing wrong ?
PF 3.0RC1 , JSF 2.0, Tomcat 7, NetBeans 7.0

saprobionte
Posts: 80
Joined: 20 Jun 2011, 15:46

25 Jul 2011, 15:53

I notice I also tried this way :

Code: Select all

InputStream test = this.getClass().getResourceAsStream("C:/test.jpg");
            image = new DefaultStreamedContent(test, "image/jpeg");
But it does not work too. I use NetBeans 7.0, Tomcat 7 and PF 3.0M3
PF 3.0RC1 , JSF 2.0, Tomcat 7, NetBeans 7.0

saprobionte
Posts: 80
Joined: 20 Jun 2011, 15:46

26 Jul 2011, 09:07

I just got back showcase package to test with, and when I try to use the DynamicImageController (changing the picture name) I got the same problem. Does someone succeed to use graphicImage with a StreamContent ?
PF 3.0RC1 , JSF 2.0, Tomcat 7, NetBeans 7.0

saprobionte
Posts: 80
Joined: 20 Jun 2011, 15:46

01 Aug 2011, 11:08

I've done many tests on this part, without success. I also looked for any bug or tips on this forum, but found nothing. I just want to know if this feature is bugged or not.

I do :

Code: Select all

<p:graphicImage id="imageSerie" value="#{tableBean.image}" />

Code: Select all

private StreamedContent image;

...

BufferedImage thumb = ImageIO.read(new File ("/images/images.jpg"));
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(thumb, "jpeg", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());
image = new DefaultStreamedContent(is, "image/jpeg");
As previous tests, it does not work. I don't think my implementation is wrong, but who knows ... Do you get some ideas on this ?
PF 3.0RC1 , JSF 2.0, Tomcat 7, NetBeans 7.0

saprobionte
Posts: 80
Joined: 20 Jun 2011, 15:46

02 Aug 2011, 15:14

I finally found a solution with a servlet. I put my servlet request as src of my graphicimage. The servlet take the right image depending on options I specify, and I update the HttpServletResponse object to fill the OutputStream with my image.
PF 3.0RC1 , JSF 2.0, Tomcat 7, NetBeans 7.0

User avatar
jim@jimtough.com
Posts: 142
Joined: 03 Jun 2011, 18:06
Location: Canada

02 Aug 2011, 15:20

Nice! I'm going to bookmark this for future reference.
PF 3.0,
Mojarra 2.1.4,
Tomcat 7.0.14,
Eclipse Indigo,
IE 7, Chrome

Image
http://stackoverflow.com/users/346112/jim-tough

Would rather be a Decepticon...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 51 guests