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}">
<cut value="${employee.name}" />
<cut 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.
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}">
<cut value="${employee.name}" />
<cut 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.