1 Reply Latest reply on Jan 12, 2010 4:37 PM by sonvegeta3

    a4j:mediaOutput don't see image

      Hello

      I have a problem, I'm tartan to display an image in firefox but not displayed.

      salida.png
      my code is as follows, all follow an example of JBOSS but I really am a rookie and I can not identify my error

       

      Code XHTML ----------------------------------------------

       

      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich">
                
          <p>Dynamically generated JPEG file:</p>
       
          <a4j:mediaOutput element="img" cacheable="false" session="false" createContent="#{mediaBean.paint}" value="#{mediaData}" mimeType="image/jpeg"/>
        
          <br/><br/>
         
      </ui:composition>

       

      Bean.java -----------------------------------------------

       

      package Media;

       

      import java.awt.Color;
      import java.awt.Font;
      import java.io.Serializable;


      public class MediaData implements Serializable{


          private static final long serialVersionUID = 1L;

       

          Integer Width=110;
          Integer Height=50;
          Color Background=new Color(190, 214, 248);
          Color DrawColor=new Color(0,0,0);
          Font font = new Font("Serif", Font.TRUETYPE_FONT, 30);


          public Font getFont() {
              return font;
          }

          public Color getBackground() {
              return Background;
          }

          public Color getDrawColor() {
              return DrawColor;
          }

          public int getWidth() {
              return Width;
          }

          public int getHeight() {
              return Height;
          }

      }

       

      MediaBean.java -----------------------------------------------

       

      package Media;

       

      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;
      import java.io.IOException;
      import java.io.OutputStream;
      import java.util.Random;
      import javax.imageio.ImageIO;

       

      public class MediaBean {

       

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

       

            Integer numero = 2300;

       

              if (data instanceof MediaData) {          

       

                  MediaData paintData = (MediaData) data;
                  BufferedImage img = new BufferedImage(paintData.getWidth(),paintData.getHeight(),BufferedImage.TYPE_INT_RGB);
                  Graphics2D graphics2D = img.createGraphics();
                  graphics2D.setBackground(paintData.getBackground());
                  graphics2D.setColor(paintData.getDrawColor());
                  graphics2D.clearRect(0,0,paintData.getWidth(),paintData.getHeight());
                  graphics2D.setFont(paintData.getFont());
                  graphics2D.drawString(numero.toString(), 20, 35);
                  ImageIO.write(img,"jpeg",out);

       

              }
          }
      }

       

      Help me pleaso .............................