Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSF database to excel

 
kenji kunoichi
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
I want make a small project in JSF in which I will feed all the values in database to be fed to an excel sheet . Right now I can connect to the database and show up all the values in JSP pages but how to take it to excel like client-machine user will just click a button and whole thing of the database will be downloaded as an excel sheet.

 
Tim Holloway
Saloon Keeper
Pie
Posts: 18276
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There isn't anything such as a "JSF database". JSF apps can use databases (or not), but JSF itself doesn't get involved with databases.

One of the simplest ways to output an Excel spreadsheet is to format a CSV text file and set the MIME type of the output to "excel". I don't remember the exact value, but it's going to look roughly like "x-application/vnd-xls" or something of that sort. The output itself won't be an XLS file, but Excel will automatically know what to do with a CSV file.

If you actually want to output something in "Excel" format - whether it's traditional XLS or XML XML, you need some heavyweight support. The Apache Poi project is good for that.

In either event, JSF is designed to output HTML, and neither of the 2 "Excel formats" nor CSV are HTML. So you're better off using a servlet or JSP to do the Excel output. Since JSF session-scope beans are actually just ordinary Servlet session objects, you can do your data entry using JSF to edit a session object (backing bean), then have your display servlet/JSF reference that session object to produce the output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic