• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to download primefaces tree in csv file?  RSS feed

 
Vivek maini
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to download primefaces tree in csv file?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Vivek!

What do you mean "download primefaces tree in csv file"? What would that benefit you? For that matter, what would you expect to see when you attempt to download a tree structure into a table format?
 
Vivek maini
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I want to export Tree structure(primefaces) into csv file
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That doesn't make any more sense now than when you first said it.
 
Vivek maini
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a bean class in which i have written the code for a tree (primefaces tree <p:tree> ) and now i want to save/download that tree data into a csv file on my pc.
Hope now you get my question.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!