0

I have a big problem and i need your help.

My application is with JSF and rich faces. I have a list of Image in my model (imageModel):

import java.awt.Image;
List<Image> liste_images = new ArrayList<Image>()

And i have to play them one by one (every 3 seconds one of them is display ) in the same place.

How can i do that with J Query ? I must send the list of image to the java Script and then display them ?

Please some help!

bipen
  • 36,319
  • 9
  • 49
  • 62
Paul
  • 45
  • 7
  • seems like you need a normal image slider to me – Spokey Jun 10 '13 at 14:01
  • Hello Spokey, Help me please ! – Paul Jun 10 '13 at 14:14
  • does your `liste_images` contain the image link? – Spokey Jun 10 '13 at 14:19
  • No Spokey my list contain Image (java.awt.Image)and not the image Link `image = ImageIO.read(new File(path_image)); liste_images.add(image);` – Paul Jun 10 '13 at 14:24
  • the easiest way would be to create a `HTML ` element, otherwise Javascript can't read it. – Spokey Jun 10 '13 at 14:29
  • thanks I will try it ! And how can i send the list of image from the model to java script ? – Paul Jun 10 '13 at 14:35
  • you can not do it directly http://stackoverflow.com/questions/13725734/how-send-image-from-java-applet-to-javascript – Spokey Jun 10 '13 at 14:39
  • and if i have a method that convert image to byte Array ! `byte[] byteArray = IOUtils.toByteArray(is);` It's possible to call this method every 3 second to change the actually image ? – Paul Jun 10 '13 at 14:49

1 Answers1

0

Well, since you are using RichFaces:

Image display

There is <a4j:mediaOutput> (link) for showing images:

<a4j:mediaOutput element="img" id="image"
    createContent="#{bean.paint}" value="#{bean.currentImage}" />

The paint method takes an OutputStream and an Object (provided by the value attribute):

public void paint(OutputStream out, Object data) {
    BufferedImage img = (BufferedImage) data;

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

assuming you use BufferedImage.

Image switching

There is <a4j:poll> (link) which makes periodical ajax requests.

<a4j:poll render="image" interval="3000" enabled="#{bean.active}"
    actionListener="#{bean.showNextImage()}" />

the showNextImage method will get the next image from the list, I'm sure you know how to do that. :)

Makhiel
  • 3,874
  • 1
  • 15
  • 21