• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic table using struts

 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 426
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic