Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display Data Records in Table

 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I use a resultset from a remote connection I get with a bean and display this on a JSP table? I am puting the resultset into an array and can put this into a list but I really need it in a table.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a JSP table.

I would avoid working directly with the database connection and/or connection from within your JSP.

A common way to do this is to write a bean that represents a single row in your table.
Loop through the result set, creating one row bean for each row in the resultset and add it to a List (java.util.ArrayList is commonly used for this). Then bind the list of row beans to request scope and forward to the JSP. From within the JSP you'll be able to use JSTL/EL to loop through the list of rowBeans to present your data as an HTML table.
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I the list of components for my JSP I have Dynamic Table. Could and how would I use this if my data is in a multi dimetenional array?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use an ArrayList of ArrayLists.

This could be iterated over with a nested set of c:forEach tags
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please give me an example of what the code in the JSP should look like? This is the code generated when I add the Dynamic Table to the page. My array is called faiArray.

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Steve Dyke:
[QBwhen I add the Dynamic Table[/QB]


What is a "Dynaimc Table"? Is it a 3rd-party tag library or some such? We're not mind readers.
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the lib I import when adding a new JSP to my project

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

In the list of components that I can choose from Dynamic Table is one of them. I wished I was more knowledgable in this area so my posts would not be so sketchy.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dynamic Table is not a JSTL "component".

In the list of components that I can choose from


What list? From where? In an IDE?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say "Dynamic Table' do you just mean that you don't know the number and names of the columns in the resultsets returned from your database query or is Dynamic Table the brand name of some third party library that you're using?

There is nothing in JSTL called Dynamic Table.
 
Steve Dyke
Ranch Hand
Posts: 1616
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Websphere Development Studio. The term Dynamic Table is the name on the component listed in the set of tools. I an earlier post it was suggested to use ArrayList and then a nested set of c:forEach tags. Can you tell me how to do the nesting so the contents of list one is in column one and list two is in column two etc?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have an IBM Web sphere forum where you are more likely to find some help with their proprietary objects.
I'll move this discussion over there.

If, you can get help getting the data into the nested lists or arrays but still need help with the JSTL tags, either ask the moderator there to move it back here or start a new topic here.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic