File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Dynamic table using struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic table using struts" Watch "Dynamic table using struts" New topic

Dynamic table using struts

NDP Prasad
Ranch Hand

Joined: Apr 13, 2006
Posts: 177

Iam new to struts. I want to create a table to display values from a database.

i want to display a particular table from database as table in struts. How can i display it?

The table may have variable number of entries at different times..for EG: if the database table has 20 entries or row, my struts table have to display those 20 entries, suppose if the number of entries in the table increases 30 it should display the 30 entries.

Can any one help me please?


rahul khanna
Ranch Hand

Joined: Sep 14, 2005
Posts: 48
First of all,not a good database design and I would recommend you to revisit it.

A bit tricky I would say and would also would depend on what are you using to database like JDBC or O/R mapping such as Hibernate.

Assuming you are using Hibernate.. every time you change the DB , you will have to regenerate the POJO classes and that would necessarily mean rebuilding and redeploying of the application.

In such a scenario, every time you change the DB you have to manually read the column count and store as a CONSTANT in the application. You can then read this variable and then get the number of columns to generate the table.
NDP Prasad
Ranch Hand

Joined: Apr 13, 2006
Posts: 177
Is it possible to know the numbers of rows and colunm in the database table and create the table in struts and display the valus in the corresponding matrix?

I mean if i have 10 employee record in database if i increased to 11, i want my struts application to read the database and dynamically create 11 records similar to that of displayed in the database.
Mark Reyes
Ranch Hand

Joined: Jul 09, 2007
Posts: 426

I had the same problem before and googled for a good site on how to implement this.

This link might be of help to you. Just replace the scriptlet tag with proper struts tags. Use logic:iterate in replacement for the for loop.

Regarding the rows and columns, I just usually process the resultset coming from the database and take note of the number of rows and columns. Afterwhich I set it as request/session attributes which will be later used in processing in my JSP page. See how the WIDTH and HEIGHT is being used in the link.

I hope I had offered some help to you.

Sean Clark ---> I love this place!!!
Me ------> I definitely love this place!!!
I agree. Here's the link:
subject: Dynamic table using struts
It's not a secret anymore!