O'Reilly logo

PrimeFaces Cookbook - Second Edition by Oleg Varaksin, Mert Çalışkan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating dynamic image streaming programmatically

The graphicImage component can also render an image that is created programmatically in the server-side backing bean.

How to do it…

The following is an example that renders a PrimeFaces logo, which is read with the resource streaming mechanism:

<p:graphicImage value="#{dynaImageBean.graphicText}" />

public StreamedContent getGraphicText() throws IOException {
  InputStream stream =this.getClass()
    .getResourceAsStream("/chapter7/primefaces.jpg");
  return new DefaultStreamedContent(stream);
}

How it works...

As seen, the getGraphicText() method returns an instance of StreamedContent. PrimeFaces also provides a default implementation for the stream content, which is org. primefaces.model.DefaultStreamedContent ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required