mediaoutput sample not working
ajanz Sep 16, 2009 4:49 AMi try to use the mediaoutput sample but can't get it work. mediadata is always null
my page is
<?xml version="1.0" encoding="ISO-8859-1"?> <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:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j" xmlns:s="http://jboss.com/products/seam/taglib"> <h:panelGrid columns="2" > <h:panelGroup id="thumbs"> </h:panelGroup> <a4j:mediaOutput element="img" cacheable="false" session="false" createContent="#{PDFImaging.paintpage}" value="#{mediaData}" mimeType="image/png" /> </h:panelGrid> </ui:composition>
java cbeans
public class MediaData implements Serializable{ private static final long serialVersionUID = 1L; Integer Width=50; Integer Height=110; 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; } } @Name("PDFImaging") @Scope(ScopeType.PAGE) public class PDFImaging { String pdfsource; String currentimage; ArrayList<MediaBean> thumbs = new ArrayList<MediaBean>(); boolean lbinit =false; public void init() { int count=0; File dir= new File("D:/seampages"); for(File f : dir.listFiles()) { if (f.isDirectory() == false) { MediaBean mb = new MediaBean(); mb.setImagefile(f.getAbsolutePath()); System.out.println("Adding " + f.getAbsolutePath()); thumbs.add(mb ); count++; } if ( count > 20 ) break; } lbinit = true; } public void paintpage(OutputStream out, Object data) throws IOException{ System.out.println("Paint page " ); if ( data != null) System.out.println(data.getClass().getName()); else System.out.println("is null!!!!"); try { if (data instanceof MediaData) { MediaData paintData = (MediaData) data; BufferedImage img = new BufferedImage(paintData.getWidth(),paintData.getHeight(),BufferedImage.TYPE_INT_RGB); img = ImageIO.read(new File("D:/seampages/1.png")); ImageIO.write(img,"jpeg",out); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getPdfsource() { return pdfsource; } public void setPdfsource(String pdfsource) { this.pdfsource = pdfsource; } public String getCurrentimage() { return currentimage; } public void setCurrentimage(String currentimage) { this.currentimage = currentimage; } public ArrayList<MediaBean> getThumbs() { if ( lbinit == false ) init(); return thumbs; } public void setThumbs(ArrayList<MediaBean> thumbs) { this.thumbs = thumbs; } }