This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we create a custom component by extending rich:dataTable?

 
Thoyyeti Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Members,


I have requirement where user wants 1. all tables to be exported to excel 2. all tables to be paginated so as to view 20 rows at a time 3. all columns in every table sortable.


1. For this can we come up with a generic solution so as not to repeat the glue code every time I create a table?

2. Can we come up with a custom component by extending the rich:dataTable ?
Am I looking at right approch?

Please suggest. Thanks for your time.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18014
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Thoyyeti!

JSF is normally setup to render output in HTML. Excel files are not HTML, so you really need an alternate renderer for them, for example, a servlet that outputs information using the Apache poi library.

Pageable dataTables are not provided in basic JSF, but most extension tagsets have a pageable dataTable component.

Making the columns sortable on the client side is a bit more trouble. If you want static sorting, you can attach actions to the column headings so that clicking on a column heading will trigger creation of a new DataModel with the rows sorted by that column. You'll have to do the sorting yourself.

If you want dynamic/AJAX sorting, use an extension tagset such as JBoss RichFaces, which has an extendedDataTable component that supports dynamic sort-by-column as well as the ability to filter what's displayed and do various other useful things.
 
Thoyyeti Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thank you for your response.

Regards,
Srinivasan

 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made a similar question earlier on this forum
http://www.coderanch.com/t/515823/JSF/java/Alternative-displaytag
and I currently use the PrimeFaces dataTable (it has the sorting and paging in it) and with that the dataExporter (that can export to excel as you wanted).

All you have to remember is that the backing bean needs to live after the first request (since the table sends ajax calls to bean when it does paging and sorting) so it needs to be in View, Session or Application scope (or in some other long living scope).
 
Thoyyeti Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ilari,

you are spot on... by the way we are bound to use rich faces alone.

Regards,
Srinivasan
 
Thoyyeti Srinivasan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ilari,

our requirements are in sync... Bad news is I am bound to use rich faces so I can not make use of existing components in other custom taglibs nor I am ready for writing a custom component. This is just luring me to have bite of unreachable grapes.

Regards,
Srinivasan

 
Ilari Moilanen
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is a bad situation indeed.
One way to accomplish the export requirement is to just do it yourself with a servlet (or JSF action). And you can look at the source code of primefaces (or the tomahawk wiki page that was behind my link) for hints on how to do it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic