Creating dynamic image streaming programmatically
With the graphicImage
component, it is possible to 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 that is read with the resource streaming mechanism.
<p:graphicImage value="#{dynaImageController.graphicText}" /> public StreamedContent getGraphicText() throws IOException { InputStream stream = this.getClass().getResourceAsStream("/chapter9/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 ...
Get PrimeFaces Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.