1 Reply Latest reply on Jul 9, 2009 8:36 AM by alan79

    Unable to embed swf movie using mediaOutput

    alan79

      Hi Forum

      I'm trying to embed a swf movie using the mediaOutput (as described in the demo). But I can't get it to work.. It just happens nothing.

      I added the request scope beans MediaBean and MediaData.

      This my page:

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      
      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:fn="http://java.sun.com/jsp/jstl/functions"
       xmlns:c="http://java.sun.com/jsp/jstl/core"
       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:t="http://myfaces.apache.org/tomahawk"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
      
      
      <f:view>
      
       <ui:composition
       template="#{facesContext.externalContext.requestContextPath}/../layout/layout.xhtml">
      
       <ui:define name="contentNav">
       <t:div id="leftContentNavigation">
       </t:div>
       </ui:define>
       <ui:define name="contentComponents">
       <t:div id="leftContentComponents">
       </t:div>
       </ui:define>
       <ui:define name="title">
       <h:outputText value="#{cont.windowTitleHelp }" />
       </ui:define>
       <ui:define name="content">
      
       <f:verbatim>
      
       <script type="text/javascript"
       src="#{facesContext.externalContext.requestContextPath}/scripts/swfobject.js" />
      
       <script type="text/javascript">
      
       var flashvars = {};
       var params = {};
       var attributes = {};
       swfobject.embedSWF(#{rich:element('swfLink')}.href, "#{rich:clientId('myFlashContent')}", "200", "200", "9.0.0", false, flashvars, params, attributes);
       </script>
      
       <a4j:outputPanel id="flashPanelDynamic">
      
       <a4j:mediaOutput element="a" id="swfLink" style="display: none;" cacheable="false" session="true"
       createContent="#{mediaBean.paintFlash}" value="#{mediaData}" />
      
       <a4j:outputPanel layout="block" id="myFlashContent" style="width: 200px; height: 200px">
       <a href="http://www.adobe.com/go/getflashplayer">
       <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
       </a>
       </a4j:outputPanel>
      
       </a4j:outputPanel>
      
      
      
      
       </f:verbatim>
      
      
      
      
      
      
      
       </ui:define>
       </ui:composition>
      </f:view>
      </html>
      


      The Beans:
      package com.antavis.groupware.handler;
      
      import java.awt.Graphics2D;
      import java.awt.image.BufferedImage;
      import java.io.IOException;
      import java.io.InputStream;
      import java.io.OutputStream;
      
      import javax.imageio.ImageIO;
      
      public class MediaBean {
      
       public MediaBean(){
      
       System.out.println("*** DEBUG MEDIA BEAN INITIATED...");
       }
      
       public void paint(OutputStream out, Object data) throws IOException{
       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.drawLine(5,5,paintData.getWidth()-5,paintData.getHeight()-5);
       graphics2D.drawChars(new String("RichFaces").toCharArray(),0,9,40,15);
       graphics2D.drawChars(new String("mediaOutput").toCharArray(),0,11,5,45);
      
       ImageIO.write(img,"jpeg",out);
      
       }
       }
      
       private void copy(InputStream in, OutputStream out) throws IOException {
       byte[] buffer = new byte[2048];
       int read;
      
       while ((read = in.read(buffer)) != -1) {
       out.write(buffer, 0, read);
       }
       }
      
       public void paintFlash(OutputStream out, Object data) throws IOException {
       ClassLoader loader = Thread.currentThread().getContextClassLoader();
       if (loader == null) {
       loader = getClass().getClassLoader();
       }
      
       InputStream stream = this.getClass().getClassLoader().getResourceAsStream("../../scripts/create_time_report.swf");
       if (stream != null) {
       try {
       copy(stream, out);
       } finally {
       stream.close();
       }
       }
       else{
       System.out.println("*** DEBUG MOVIE - STREAM NULL...");
       }
       }
      }
      

      
      package com.antavis.groupware.handler;
      
      import java.awt.Color;
      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(0,0,0);
       Color DrawColor=new Color(255,255,255);
       public MediaData() {
       }
       public Color getBackground() {
       return Background;
       }
       public void setBackground(Color background) {
       Background = background;
       }
       public Color getDrawColor() {
       return DrawColor;
       }
       public void setDrawColor(Color drawColor) {
       DrawColor = drawColor;
       }
       public Integer getHeight() {
       return Height;
       }
       public void setHeight(Integer height) {
       Height = height;
       }
       public Integer getWidth() {
       return Width;
       }
       public void setWidth(Integer width) {
       Width = width;
       }
      }
      


      It seems like the MediaBean class is never initiated.. What am I doing wrong?
      Thank you very much for a hint!
      Best regards
      Alan