O'Reilly logo

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

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

Downloading files

The fileDownload component can be used to stream binary contents such as files to requesting browsers, by wrapping the components with any JSF command component such as a button or link.

How to do it...

The value of the fileDownload component should be an instance of org.primefaces.model.StreamedContent. The concrete class org.primefaces.model.DefaultStreamedContent could be used for simple purposes. The following is the backing bean implementation for the file download example along with the component definition.

public class FileController implements Serializable { private StreamedContent file; public FileController() { InputStream stream = this.getClass(). getResourceAsStream("/chapter7/PFSamplePDF.pdf"); file = new DefaultStreamedContent(stream, ...

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