I have an image byte[], this byte[] is coming from LDAP [Oracle Open LDAP Authentication Provider] and I need to show this image into the page.
How can I do this?
Can I use javax.faces.context.ResponseWriter to write the byte[] or I should extract an instance of java.io.OutputStream from the javax.faces.context.FacesContext and write the byte[] into page.
If any one of these methods is possible, then I can might be able to create a custom JSF tag, to display the image, and try to execute the image creation in encodeBegin(FacesContext context, UIComponent component) method of the javax.faces.render.Renderer, where the byte[] will be send as attribute.
Can I use Servlet for this purpose? Actually I don’t know whether or not I can call a Servlet from the source attribute of the af:image.
It will be very helpful to me if I get your suggestion.
Thanks.
You need to think of this at the HTTP level. The page doesn’t contain the image (at least unless you’re going to embed the data directly, which is almost always a bad idea for non-tiny images). It contains a URL to the image.
You should produce an
imgtag with an appropriatehrefwhich will allow you to fetch the data when the browser makes a request for it. That should almost certainly be a separate servlet, for simplicity – ideally responding to requests which include a “reasonable” filename (with a reasonable extension for the image).At that point you fetch the data for the image and write it not to a
Writerbut to anOutputStreamfor the response, as it’s binary data.