Primefaces data export for nested datatables and dynamic columns - java

I have an outer DataTable that has only one column, and each row is a sub DataTable. The number of sub data tables varies based on number of elements of the list that is accepted from the outer database. In the sub datatables i use dynamic columns. I need to export the data that appears to pdf/excel. The primefaces exporter doesnt support nested datatables. i've seen this answer but it provides no answer to the dynamic columns issue: Primefaces dataExporter and nested dataTable
Any help is welcomed, cause im on a tight deadline.

You may have a look on Primefaces Extensions exporter.
There are samples of code concerning export of subTables and dynamic columns

If exporting is really important, I suggest you create a pure table.
You could then call a method using iText (2.1.7 version should work). It offers the advantage of having full control over data exportation.

Related

Tosca angular table steering

I am a tester in a Scrumteam trying to automate our test regressionset.
Our front-end is developed in Java Angular and we use Tosca testsuite to automate our testset. The problem I am encountering is as follows:
With Tosca you can scan the application and all the fields, atributes, divs, and so on are shown to the user. The moment I scan one of our datatables I see them as what they are: a table. However, every field/button/icon/etc is being scanned as a seperate object.The table has 1 body, but the individual rows are not found. Meaning that the rows within the tables are not identified.
This makes it impossible for me to perform an automated search on a table, because the rows and therefor the colums are not identified, only the header is.
Anyone ever encountered this issue with a testtool or found a sollution how to fix this in the coding of the front-end in Java Angular?
This is a common scenario when the application under test is developed using UI Libraries, where the complex controls (e.g. Table, Combobox etc.) are rendered not as a single HTML tag (<TABLE> for Table or <SELECT> for combobox). Instead you will find bunch of other HTML tags (<DIV>, <SPAN>, <TABLE>, <UL> and what not!)
If I understood correctly, there are two ways to automate this scenario -
You mentioned that you are able to find a <TABLE> tag (The header). There good
chances that each row in the table is itself a <TABLE> and that's
why you are not able to see all the contents in a single one (you
can cross check this in the Content View section of XScan
window). If you just need a single row for verification (I am just
assuming!), you can select any one of them and use ConstraintIndex to get to the right row data. You can also look for a parent control (basically another <TABLE>) which clubs all the child table. This parent table might show all the data in one place. Table Verification will work with this control. Please remember that it is
just a workaround and might not fit into your scenario.
You can write a custom control to handle this. Custom control is a way where user can define how a control looks like. Once you implement this, Tosca will be able to recognize the table as a single control containing all the data. For more information on this, check the Tosca API reference here

Pagination and sorting

I am using spring mvc,IOC and hibernate in my project. I am reading the records from the database and displaying them in a grid
I need sorting and pagination on table records
I used jquery tablesorter for sorting. My Problem is that i want to implement server side pagination not client side.So in case of table sorter when somebody will sort some column and click on next page then client side sorting will fail.
Is there library or api for implementing server side pagination and sorting?
Thanks
Ramandeep Singh
If it is an option for you to use Spring Data for your repository layer then this supports server side sort and page out of the box with integrations for your controllers.
http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/repositories.html#web-pagination
I have used it with DisplaTag without any issues but should work with any table component. Configure either the component or Spring Data so the sort/page param names match up.
Also vastly reduces much of the boiler plate code around creating JPA repos. Much of the time all you need do is create an interface and leave the implementation to the library.
Well worth a look.
For this purpose, you have to send these values from jsp page to your action method (1)Current Page Number(2) ColumnToSort (3)No of records on page you want to see
and you have to apply to some logic on server side to calculate starting and ending record
then you can use hibernate query's (1)setFirstResult (2)setMaxResults functions.
You can use "order by" in your query for sorting.

How to load dynamic content in JSF table

I have a webpage with a table layout in it which is develop using JSF. The data, including header and content value, inside the table should be dynamically load. My current challenge is different source coming into this JSF page will have different row's of records. May I know how this can be done? Am I require a Java Bean to achieve my objective?
You can easily use beans for that. Usually the content of the table will go from the database. So in the datatable you can just use value="#{yourbean.contentList}". And the contentList will be retrieved based on the id of the desired data which can be set by the request params.
JSF datatable do not have a limit on the number of rows. If there are a large number of rows the browser may not handle it well, use paging to limit the number of rows http://balusc.blogspot.com/2008/10/effective-datatable-paging-and-sorting.html
If there are different numbers of columns (not rows) in the data then dynamically generate datatable http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDynamicDatatable
Thanks to BalusC!

processing a jsf datatable

I've a page with a datatable which can be considered a view on a table of a database. Some fields are static, but some others are inputText, which are meant to modify that field (in particular, all the fields of a specific column).
I would like to press a button and save the whole table.
In general, I'd like to understand how to read an entire table in a managed bean.
Thanks!
EDIT:
I'll try to be more clear:
imagine you've a NxM table of only inputText. Outside the table, a button with an action like #{SomeBean.process}. I'd like to have, in that process method, a List with length N and Row is an object with M fields.
If I understand correctly
I think, you need to save not a datatable, you need to save a rows from this table. With JSF you can use binding and when you need to save data, you just get rows from this binding and make data operations.
If you used some kind of object-relatational mapping like JPA it would be quite easy. Then you could create an entity class of your database table and fill your datatable with a list of your entity objects.
Then you could submit the whole datatable and merge all the changes with your database.
Some IDEs like Netbeans even create entity classes automatically with the help of a wizard. If you are on Netbeans, I recommend to read the JSF Crud tutorial. For Eclipse there should be similiar tutorials, but I am not so familiar with this IDE.

Create graphs and charts in Java Swing application using MySql ResultSet data

I have heard of JfreeChart but is there any general steps for using data returned from an SQL query to create graphs and chart.
I have an application that shows as a menu option "Analytic's", this Jframe window uses complicated query to retrieve data using business logic but i want to then display this data in a more viable way (rather than a long Jtable result). How can i filter my data and create a graph for the user to analyze?
Check java2s.com/Code/Java/Chart/CatalogChart.htm for a lot examples.
Generally you can fill your own dataset based on your ResultSet. But if you are query is returning results close enough to what you are loading into your dataset you can just use the JDBCCategoryDataset from JFreeChart.
Since you are in search... I think that there is no better tool for designing and generating reports and graphs from your database than iReport. It offers a very consistent GUI, and gives you all support necessary to start creating business graphs from your database data.
The produced report is dynamic. Can be embedded into any application. The reports can be exported as PDF, XML, XHTML, .doc, .odt and more ways. One can pass variables to the report at run-time like from-to Dates, code-id's etc.
iReport is built on top of JasperReports. It is free and open source.
Let me make also clear that i am not in any way affiliated with iReport! :-)

Categories