labs / tiddlers / content / labs / lab07 / _Labs_07_Perform the
@Mark George Mark George on 22 Aug 1017 bytes More fixes

There is already a for loop being used to generate the table row that contains the student's details. This loop is using the a collection of students that is retrieved from the DAO. All we need to do is replace that collection with the students that we want to be displayed.

Replace the existing code that retrieves the students from the DAO with the following:

    // get the major from the query parameter
    String major = request.getParameter("major");

    // declare the students collection
    Collection<Student> students;

    // if there is no major parameter, or "All" is requested, return all students
    if (major == null || major.equals("All")) {
        students = dao.getAll();
    } else {
        // otherwise, get the students for the requested major
        students = dao.filterByMajor(major);

Modify the for-loop so that it is using the students collection rather than accessing the DAO directly.

Restart and test your system. You should now be able to filter by major using the links above the table.