Reputation: 10288
I have a web app (JSF 2.0) that should display some images.
I read in this thread and implemented an image servlet to send images to the client. Problem is, I am not using a database nor fixed location on the hard drive, just a backing java method returning a byte[] (For the discussion, let's say it's generated on the fly)
I am wondering if there is a 'standard' solution for this problem, namely, How do you display an image that is generated on the fly on a webpage?
UPDATE
I eventually decided to use RichFaces
MediaOutput
Component.
The answer that is marked as correct is, in my opinion, more robust and better for most cases.
Upvotes: 2
Views: 1430
Reputation: 1108722
Move the byte[]
code generating logic from the backing bean to the image servlet. All basic parameters which the backing bean uses to generate the byte[]
should be passed as request parameters to the image servlet. E.g.
<img src="imageservlet?param1=#{bean.param1}¶m2=#{bean.param2}" />
If that is really not an option for some reason, best what you could do is to let the backing bean store those images temporarily on temp disk or session and then pass its identifier as request parameter so that the servlet can locate it and write it to the response body.
Upvotes: 1