aspose file tools*
The moose likes JSF and the fly likes Can we create a custom component by extending rich:dataTable? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Can we create a custom component by extending rich:dataTable?" Watch "Can we create a custom component by extending rich:dataTable?" New topic
Author

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

Thoyyeti Srinivasan
Greenhorn

Joined: Nov 28, 2007
Posts: 4
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

Joined: Jun 25, 2001
Posts: 16014
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Thoyyeti Srinivasan
Greenhorn

Joined: Nov 28, 2007
Posts: 4
Hi Tim,

Thank you for your response.

Regards,
Srinivasan

Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
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

Joined: Nov 28, 2007
Posts: 4
Dear Ilari,

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

Regards,
Srinivasan
Thoyyeti Srinivasan
Greenhorn

Joined: Nov 28, 2007
Posts: 4
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

Joined: Apr 15, 2008
Posts: 198
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we create a custom component by extending rich:dataTable?