-
1. Re: Displaying Picture from blob
stephenwilliams Jan 11, 2007 10:56 AM (in response to vice)I would also be very interested in an answer to this question as I am trying to do the same thing. I have already implimented this with a servlet but I would like to do using a statefull session bean.
If anyone could please explain how this can be done I would be very greatfull indead.
Regards,
Stephen -
2. Re: Displaying Picture from blob
pmuir Jan 11, 2007 11:02 AM (in response to vice)I wrote a sample solution http://jroller.com/page/pmuir?entry=dynamicimagecomponent_for_jsf, also, I believe Ajax4JSF contains the 'media' component which does this and more.
-
3. Re: Displaying Picture from blob
stephenwilliams Jan 17, 2007 9:13 AM (in response to vice)Hi
Thanks for the answer petemuir!
I would like to get he Ajax4jsf solution working as everywhere I read it should just work with seam 1.1 GA but I am have a problem...
I get the error...javax.el.ELException: /home.xhtml: Bean: demo.PaintBean$$EnhancerByCGLIB$$6f0837bd, property: paint at com.sun.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:53) at com.sun.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:39) at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:232) at com.sun.facelets.tag.jsf.ComponentSupport.encodeRecursive(ComponentSupport.java:239)
I added the following in my facelet...<a4j:mediaOutput createContent="#{hello.renderImage}" value="#{hello.value}.jpg" element="img" mimeType="image/jpeg" />
the following to my bean...public void renderImage(OutputStream out, Object data) throws IOException { BufferedImage img = new BufferedImage(100, 50, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = img.createGraphics(); graphics2D.setBackground(Color.BLACK); graphics2D.setColor(Color.WHITE); graphics2D.clearRect(0, 0, 100, 50); graphics2D.drawLine(5, 5, 100 - 5, 50 - 5); graphics2D.drawChars(new String("Ajax4JSF").toCharArray(), 0, 8, 40, 15); graphics2D.drawChars(new String("mediaOutput").toCharArray(), 0, 11, 5, 45); ImageIO.write(img, "jpeg", out); }
the following to my interface...public void renderImage(OutputStream out, Object data) throws IOException;
and then deployed it.
If anyone has allready done this I would really appreciate a small example. -
4. Re: Displaying Picture from blob
pmuir Jan 17, 2007 9:46 AM (in response to vice)Probably you are better off asking this on the ajax4jsf forum/mailing list (whichever they use) as it's relevant to that than to Seam.
-
5. Re: Displaying Picture from blob
stephenwilliams Jan 17, 2007 10:23 AM (in response to vice)I have gotten one step further, hurray! My problem was that the ajax4jsf jars (ajax4jsf.jar and oscache-2.3.2.jar were not being deployed.
I now have the same problem that has been posted at
http://jboss.com/index.html?module=bb&op=viewtopic&p=3999655
I will continue there. -
6. Re: Displaying Picture from blob
smokingapipe Jan 17, 2007 2:46 PM (in response to vice)I haven't looked at Peter's solution but I know it would be quite easy and efficient to write a plain old Servlet to do this. It is perfectly possible to use EntityManagers within Servlets, and serving an image from a Servlet is a good way to go. You avoid any overhead of Seam, JSF or anything else, and it can be done with just a few lines of code in a servlet.
-
7. Re: Displaying Picture from blob
shane.bryzak Jan 17, 2007 6:10 PM (in response to vice)The Seamspace example in CVS serves images from a servlet, and provides an image rescaling feature also. Take a look at ContentServlet.java, it's pretty straight forward - and it uses SeamServletFilter to set up the Seam contexts.
-
8. Re: Displaying Picture from blob
stephenwilliams Jan 18, 2007 4:12 AM (in response to vice)Thanks guys!
I will check it out. Ideally I would like to have a statefull bean that handels all the attributes and generates the image. Of couse if I don't manage this I will also try out peters solution or just a plain servlet.