How to use dynamic p:graphicImage with StreamedContent?
I try to use a dynamic p:graphicImage with a StreamedContent object but nothing is displayed. The img tag is rendered in the html markup but with firebug I can see that the img src attribute is causing a 404 - not found error.
I'm using a similar approach as described [here][1].
In a custom java class I'm generating a StreamedContent object from a previously uploaded image. In an ivy script block I'm assigning the return value to a dataclass attribut of type StreamedContent.
Here some code snippets:
java class MyImageUtil:
public StreamedContent retrieveImageAsSC()
{
...
StreamedContent sc = new DefaultStreamedContent(inputStream, mimeType, fileName);
return sc;
}
...
ivy script block:
in.myDataClass.streamedContent = myImageUtil.retrieveImageAsSC();
...
jsf xhtml:
p:graphicImage value="#{data.myDataClass.streamedContent}" />
The following URL is generated for the img src attribute:
http://localhost:8081/ivy/faces/javax.faces.resource/dynamiccontent.properties?ln=primefaces&pfdrid=pfdrid_945697ac-ead2-49e3-af3c-4185184fe927
which isn't accessible.
[1]: http://answers.axonivy.com/questions/261/how-to-set-content-type-of-a-download-of-a-filehttp://answers.axonivy.com/questions/261/how-to-set-content-type-of-a-download-of-a-file
---
After a bit of research and debugging it seems to be an ivy designer bug :).
As described over at [stackoverflow][1] you should use a method expression for the value attribute of the p:graphicImage. This method should be called twice:
1. while rendering the html markup so the img tag is getting generated
2. when the browser actually requests the image
In ivy this method is only called **once**. I've tested it with v5.0.16 and v5.1.4 to no avail.
As the mentioned solution from stackoverflow is working in a standalone jsf web application I assume that this is an ivy designer bug. I'm looking forward to any feedback to solve this issue.
[1]: http://stackoverflow.com/questions/8304967/how-to-use-pgraphicimage-with-streamedcontent-within-pdatatable