JSTL displaying relational data on a JSP

Discussion in 'Java' started by Carse, Jan 26, 2005.

  1. Carse

    Carse Guest

    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.
    Carse, Jan 26, 2005
    #1
    1. Advertising

  2. Carse

    Carse Guest

    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


    Carse wrote:
    > 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.
    Carse, Jan 28, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. asj
    Replies:
    0
    Views:
    362
  2. shahbaz
    Replies:
    0
    Views:
    888
    shahbaz
    Oct 27, 2003
  3. Robert Mark Bram

    Custom JSTL that accepts JSTL expression

    Robert Mark Bram, Dec 15, 2004, in forum: Java
    Replies:
    0
    Views:
    953
    Robert Mark Bram
    Dec 15, 2004
  4. Replies:
    0
    Views:
    4,335
  5. DaFoot
    Replies:
    1
    Views:
    1,669
    DaFoot
    Oct 23, 2008
Loading...

Share This Page