How to load dynamic content in JSF table - java

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!

Related

Java Displaytags: custom column with form and action

Java Tomcat application.
I am using displaytags to render tables with data.
I am passing the List from my application and JSP displaytags is just rendering it (and displaying). I need to use displaytags to have a possibility to sort tables based on different columns.
But right now i need to have the action (form) for each row - to have a possibility to remove that record from mysql database.
Is there any possibility to add one more column using a custom value (with a form with custom value derived from every record id) ?
Thanks,

Can a Derby database contain rows with different numbers of columns?

ie, I want to dynamically create extra columns for specific users if required from the JSP pages of my web app - is this possible, or is there another way of achieving the same thing?
Short answer is no. Every row in a table must have the same number of columns.
If there is no applicable value for a column one typically inserts NULL (SQL NULL which is different from Java null). Alternatively you could change your data model and put the optional values in a different table, and use a join when you want to read the optional columns.
Finally, you could also represent the optional info in a Java object and serialize that into a Blob which you store in your table, but I would caution you against this approach since it prevents you form querying on the values in the Blob and you get an upgrade problem if the format of the Blob object changes.
Hibernate allows you to dynamically create database table provided
you know rows and columns
If you dont want to add that and still keep it simple and sweet use "<% scriptlet %>" codes in jsp containing Java code to create or modify table
Instead of using scriplet you could use Struts / JSF/ Spring tags for cleaner code

Primefaces data export for nested datatables and dynamic columns

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.

how to generate multiple tables using displaytag in jsp dynamically?

Hey i have to generate multiple tables. User request for some thing say details of houses,so the respective data is retrieved from the database and then some calculation is performed and tables have to generated accordingly. So it depends on the request of the User for eg. if he select 3 houses then i have to display 3 different table with respective data in it and if 4 houses then 4 tables. In all a dynamic jsp.
I know there is some way using displaytags. I'm new to this technique. And also are there any good tutorials on displaytags apart from its home site to make my understanding for it more thorough?
Thanks
These can help you.
Display tag library 1.2
Pagination Using Display Tags
Display Tag Examples

slow Rendering data into table using display tag liabrery

I am using displaytag 1.0 in my Struts base application. I have 5 million rows to showing reports of all rows data by paging with 50 records. It takes 5 minutes to rendering the data. Can we reduce this one? Please suggest how make it with in one minutes.
It is apprently hauling the complete database into Java's memory instead of only the data of interest (the current page). You'll need to introduce request-based pagination at the DAO level.
To start, in your DAO class do a SELECT stuff FROM data LIMIT firstrow OFFSET rowcount or something like that depending on the DB used. Then in your JSP create a HTML table yourself with help of JSTL c:forEach or Struts' logic:iterate. Keep one or two request parameters in the background in a input type="hidden" element: the first row to be displayed (firstrow) and eventually the amount of rows to be displayed at once (rowcount). Finally provide a bunch of buttons which instructs the server side code to in/decrement the firstrow with rowcount everytime. Just do the math.
You can find a more detailed answer here.

Categories