JSTL displaying relational data on a JSP

C

Carse

Hi,

I want to display data from two related database tables on a JSP page
as follows:

Employee Name | Company Name
----------------------------
Jack | SomeCompany
Ruth | AnotherCompany

In the DB, I have two tables:
- Employee table with EmployeeID (primary key), CompanyID and Name
- Company table with CompanyID (primary) and Name

I have a ListEmployeesAction class that fills a collection with the
employee data and fills a HashMap with the company data. The keys in
the HashMap correspond to the primary keys for each company. The
collection and HashMap are populated through calls to EmployeeDAO and
CompanyDAO and passed to the JSP page
[request.setAttribute("employeeList", empCol) and
request.setAttribute("companyList", companyMap) ].

On my JSP page I want to do this:
<c:forEach var="employee" items="${employeeList}">
<c:eek:ut value="${employee.name}" />
<c:eek:ut value="${companyList[employee.groupID].name}" />
</c:forEach>

---
My first question:
the company name doesn't get displayed at all, even though i know for
sure it is being generated properly and the primary keys match. Am I
accessing the HashMap improperly? (I'm using
map.put(Integer.valueOf(companyID), company) to populate the map in the
DAO)

My second question:
Is this designed properly? Someone mentioned setting up a class
containing string variables that directly corresponds to the data I
need to display in the table. This seems wrong to me if I consider the
case where I have 100 employees from the same company. This means I
would be storing 100 duplicate company names whereas in my current
design I would only be storing 1 and referencing it by primary key.
Many thanks in advance for your time and consideration.
-Carse.
 
C

Carse

The solution to my first question was to convert all of the IDs to
Strings and store the object in the HashMap with a string key. The
dynamic lookup works perfectly now!

After spending nearly a week trying to figure out the best way to do
this and feverishly wrestling with Java and JSTL I no longer care about
my second question.

Thank you to all who responded. :p
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top