1 Reply Latest reply on Feb 20, 2012 8:40 AM by fuubah

    a4j:mediaOutput and bytearray from database

    fuubah

      Hi all,

       

      this is my first post, i hope it is the right place.

      I cant get the a4j:mediaOutput working.

      if followed some howto's , googled and modifieded code from here.

      http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_mediaOutput.html

       

      Im using glassfish 3.1 and richfaces 4.1. both are working( i created some tables and calendars.)

      My problem is that i cant render my bytearray with that component.

       

       

      I changed the paint method from the documentation to this :

       

      public void paint(OutputStream out, Object data) throws IOException{

       

              byte[] imageData = ### call Method which returns a ByteArray ### ;  <---- i removed the methodcall just in this post

              BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData));

             

              ImageIO.write(img,"jpg",out);

       

          }

       

      in my index.xhtml i wrote this.  the rest is 1:1 as in the documentation.

      <a4j:mediaOutput element="img" cacheable="false" session="false" createContent="#{mediaBean.paint}" value="#{mediaData}" mimeType="image/jpeg"/>

       


       

      I tried the same with primefaces p:graphicImage in a separate project and it is working without problems :/ but i want to use richfaces.

       

      you would really help me if you show me what i am doing wrong. Or tell me how to render a BLOB from a database in pure jsf. or post a link to someone uses mediaoutput with BLOB / bytearray image

       

      thanks in advance

        • 1. Re: a4j:mediaOutput and bytearray from database
          fuubah

          got it working with pure JSF, i wrote a servlet. In case anyone wants to know how i post the code.

           

          @WebServlet("/imgservlet")

          public class imgservlet extends HttpServlet {

           

                    private static final long serialVersionUID = 1L;

                         

                    public void doGet(HttpServletRequest request,    HttpServletResponse response) throws ServletException, IOException{

                                     

                        byte[] imageData = ### call method which returns a ByteArray ### ;  <---- i removed the methodcall just in this post

                   

                        response.reset();

                        response.setContentType("image/jpg");

                        response.getOutputStream().write(imageData);

                        response.getOutputStream().flush();

                    }

          }

           

          code in the index.xhtml:

          <h:graphicImage value="/imgservlet"  />

           

           

           

          But i still not know how to do this with mediaoutput, would be cool if someone can help me.

          1 of 1 people found this helpful