How to export an OpenFaces DataTable in Excel/CSV Format? - jsf

Unfortunately, OpenFaces Datatable has not yet an export capability unlike Primefaces or IceFaces.
While Exporting is a piece of cake, filtering an IceFaces or primefaces datatable is less easy, Yet primeFaces's filtering does not work with JSF DataModel (sad but true).
Using OpenFaces DataTable filtering is a piece of cake and so handy and powerful.
But how about The end user who wants to export a datatable that s/he filtered, to a format like CSV or MS Excel.
The great Dmitry from OpenFaces, gave me a hint :
Use OpenFaces DataTable method: getDisplayedRowDatas() that will grab the currently displayed rows from a datatable, then use some thrid library like Itext to export in PDF for example.
In my head, this should go this way:
Create a backing bean for this purpose.
Add Apache POI third library to the classpath
Write code using Apache POI to export the content of the OpenFaces datatable with its method getDisplayedRowsDatas() - but I am afraid this method does not return the names of columns' headers - or grab the HTML table rendered by an OpenFaces Datatable as a buffered string and use Apache POI to produce an Excel file streamed with the Buffer.
In the MyFaces example I came across recently: MyFaces Datatable Export Example, the developer uses Myfaces component <t:buffer value=#{myExportBean.myBufferString}> datatable here </t:buffer /> to transform the content of the datatable to a buffered String which makes things easier. JSF Core does not have such component unfortunately.
Did someone come across this before? Help or better alternatives are much appreciated.

You can check out the experimental DataTable export API, which is available in the current nightly build. We'll declare this API officially if it stands the test of time. For now, only CSV export is available, but you can write your own exporters for other formats. Here's the code that you should put in your action handler to make it work:
DataTable myTable = Faces.component("form:myTable", DataTable.class);
myTable.export(new CSVTableExporter());
It exports the data for all of the rows and columns as currently displayed by the table (only the current page of a paginated table is exported currently).

Related

Is it possible to use PrimeFaces dataTable in IceFaces environment?

I have an application using IceFaces 3.3 (non-EE version) for user interface. I would like to replace some of the pages to PrimeFaces.
As a trivial case, I created a new page with only HTML and PrimeFaces tags on it. There is a sortable and filterable lazy dataTable on the page and nothing else. The table first loads fine but when I initiate a sorting or filtering operation, the entire table disappears.
When I inspect the page, I see IcePush is operating and the IceFaces Bridge is loaded. In case of the above mentioned partial page reload, in the response XML, the dataTable appears within delete tags however, it should be present within update tags instead.
It seems that adding org.icefaces.subtreeDiff=false to web.xml solves the problem.

Generic CRUD using JSF and PRimeFaces

I was looking for some general guidelines for creating a generic CRUD page using JSF (2.1) and PrimeFaces (5.0)(specifically using PF's <p:dataTable> component). Some of my requirements are as follows:
Dynamic number of columns (based on the #of columns of a selected Database Table)
Inline editing
Popup (dialog) edit
I have tried using <p:columns> component to show the dunamic #of columns, however, it seems I cannot use the inline editing feature <p:rowEditor> when I use <p:columns>
Any help in terms of suggestions/recommendations is highly appreciated. My goal is not to create seperate pages for each table but to use the same page (component) for multiple DB tables.

Pagination for ArrayList in JSF2

I have one searched arraylist that i am getting from Database for that array list i want to apply paginataion with links First, Prev, Next, Last and Goto page dropdown here i don't want to call database for every request(i.e First,Prev,etc) i want to use arrylist that returned at the time of search.And one more requirement is field level sorting need to do Ascending,descending if user clicks on header field.can any one help me to fix this i want to use only JSF2 no RichFaces,etc
Thank in advance.
Why do you not want to use rich or prime faces or others? Just use primefaces datatable with paginator="true".
If you don't want it, but want to do it the hard way. I suggest you fetch everything from database. Use a datatable and in the getter of that table, you only give back a portion of your array. (index 10 to 20, or index 20 to 40 or...)
On top or bottom of your datatable you put some outputlinks. These can set the indexes you want to retrieve.
Hope my explanation is clear.
In case Myfaces Tomahawk is an option for you...
I see it (Myfaces Tomahawk) as a bit different from PrimeFaces/Richfaces cause MyFaces are responsible for the MyFaces JSF Implementation as well (so it could be an excuse for using Myfaces Tomahawk), so you can use the Myfaces JSF implementation + Myfaces Tomahawk
Take a look at the Myfaces Tomahawk datascroller

Help needed to create a Search page using JSF, EJB, JPA & Primefaces with Pagination

I am trying to make a search page using JSF, EJB, JPA & Primefaces with Pagination from an Oracle database table.
The page has two regions (1) region for entering search parameters
(2) region with a datatable showing the search result. This datatable supports pagination.
I have used standard code generated using Netbeans IDE, but dont know how to pass the parameters while clicking the search button and show the results based on the search in the datatable.
Please help me with sample code.
Thanks in advance.
For the input, just use a normal form like as you've created in a hello world tutorial. For presentation and pagination of the results, use PrimeFaces LazyDataModel. See also their showcase example.

Make editable rows in Datatable

I have list of rows displayed on the screen. These rows are iterated using the JSF datatable component. Now my requirement is to edit any particular row which user clicked.
Is there any way to make the fields editable while user clicking the row. Then user will fill the details and save it.
Any suggestions would be appreciated.
Creating editable data tables is very easy with jsf. Here is a good tutorial on this. But "making it editable when user clicks on it" is not supported out of the box. And this is where JSF shines, you just need to find for a JSF component (open source or commercial) compatible with your JSF (1.x or 2.x) version and start using it.
My first suggestion for you is to check and see if PrimeFaces provides this kind of component. Here is the component you are looking for.

Resources