This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dynamic table using struts" Watch "Dynamic table using struts" New topic
Author

Dynamic table using struts

NDP Prasad
Ranch Hand

Joined: Apr 13, 2006
Posts: 177
Hi,

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?

Thanks
Deviprasad


SCJP,SCWCD<br />
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
Hi,

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: http://aspose.com/file-tools
 
subject: Dynamic table using struts
 
Similar Threads
JTable problem, urgent!! Please help!!!!!
Sorting the fields of a table
paging through struts
GWT deployment on a struts 2 web app
Getting wrong auto_increment number when inserting into database table.