a4j:mediaOutput id = "telephone" element = "img" mimeTye = "image/png"
createContent = "#{imagePainter.drawImage}"
value="#{object.instance.objectId}"
in this code the object id is handed to the drawImage funtion - this function then looks up the record and populates et which has a byteArray stored on it - it then writes this out to the screen using a file output writer
@Name("imagePainter")
public class ImagePainter {
@In("midasEntityManager")
private EntityManager em;
public void drawImage (OutputStream output, Object emblemTemplateId) throws IOException{
Object et = em.find(Object.class, objectId);
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(et.byteArrayData());
FileUtilities.write(byteArrayInputStream, output, 1024);
}
/* private List}
public static void write(InputStream input, OutputStream output, int bufferSize) throws IOException {
byte[] buffer = new byte[bufferSize] ;
int readSize = -1 ;
while ( (readSize = input.read(buffer)) != -1) {
output.write(buffer, 0, readSize);
output.flush();
}
try {
input.close();
} finally {
output.close();
}
}