Ah. When you said "Primefaces tree", I thought you meant the
JSF component tree for a Primefaces webpage. You're actually asking about a Primefaces control.
You can't download controls. They are graphical and they are ephemeral. What you want to download is the data
behind the control. Its
Model. Primefaces isn't designed to simply cough up the raw model data to an end user (it would probably be a security issue, if nothing else). But you can implement code to download the model data itself and for that, not only do you not need Primefaces, you don't even need JSF. You can do that with a simple
JSP or
servlet. And would be better doing so, since you want data and JSF is intended to return HTML.
The first requirement is that you make the model object for the control be in Session scope, since any lower scope would be destroyed when you dispatched the page that downloads your data and since you're going to be referencing the data from a different view, you need a common source. JSF session scope and
J2EE session scope are the same thing (just different ways of constructing beans), so session scope will do it.
You can output a CSV from the model by simply prototyping the CSV lines on a JSP template (set content-type to text/csv or something like that). For example:
There is a catch, however. CSV files are expected to contain a homogeneous set of rows. Trees can contain model elements in all sorts of different formats. For that reason, it's common to output tree-structured data in JSON, YAML or XML formats.