Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 24822
172
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tim,

Thank you for your response.

Regards,
Srinivasan

 
Ranch Hand
Posts: 199
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made a similar question earlier on this forum
https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic