Blackboard Building Block Development - Setting The Initial Sort For An inventoryList
Introduction
We needed to display a list of Blackboard Course objects on a view page and wanted the list to be sorted by a specific field (courseId). We used the inventoryList Blackboard tag to display the list. Consulting the Blackboard Learn Building Blocks Tag Library Guide for Release 9.0 and 9.1, I found that the inventoryList tag has an attribute, initialSortCol with this description:
The column to initially sort by when the list is displayed. The value should match the name of a list element.
So we set the value of initialSortCol to be the name value for the listElement tag that displays the course ID for each Course object in the collection. But the list of Course objects still was not sorted correctly.
Thanks to some bright colleagues where I work, we were able to get the list sorted correctly. Hopefully this article will save other developers hours of frustrating work caused by incomplete and missing Blackboard documentation.
Blackboard Tags inventoryList and listElement
Below is the initial code we tried to use to display the list of Course objects sorted by courseId.
<bbNG:inventoryList collection="${allCourses}" objectVar="course" initialSortCol="courseId"
className="Course" emptyMsg="No data to display" showAll="true">
<bbNG:listOptions allowShowAll="false" allowEditPaging="false" />
<bbNG:listCheckboxElement name="selectedCourseId" value="<%= course.getCourseId() %>" />
<bbNG:listActionBar>
<bbNG:listActionItem title="Click Here To Select One or More Child Courses" id="makeChildCourse"
url="javascript:document.mainForm.submit();" contextMenuItemId="selectedCourseId" />
</bbNG:listActionBar>
<bbNG:listElement label="Course Id" name="courseId"
isRowHeader="true">
<%=course.getCourseId()%>
</bbNG:listElement>
<bbNG:listElement label="Course Name" name="courseName"
isRowHeader="false">
<%=course.getTitle()%>
</bbNG:listElement>
</bbNG:inventoryList>
The collection of Course objects displayed correctly but they were not sorted by the courseId value. Despite much trial and error we could not figure out how to sort the list. We seemed to be following the instructions for how to use attribute initialSortCol.
Blackboard Tag beanComparator
By chance we ran across the Blackboard tag beanComparator as we were being taught Building Block development by a Blackboard consultant. This tag is not found in the Blackboard Learn Building Blocks Tag Library Guide for Release 9.0 and 9.1. But from the material provided by the Blackboard consultant we learned that you must use the beanComparator tag inside a listElement to tell the list how to sort by that column. The beanComparator tag has a property attribute whose value is the field name for the class being displayed in the list that the column should use when sorting.
So we modified our code to include the beanComparator tag in the listElement for courseId and everything then worked. The list was sorted initially by courseId.
Here is the correct code for the listElement.
<bbNG:listElement label="Course Id" name="courseId"
isRowHeader="true">
<bbNG:beanComparator property="courseId"/>
<%=course.getCourseId()%>
</bbNG:listElement>
Summary
So we learned that if you want to use the initialSortCol attribute to have your inventoryList sorted when it first displays you must include a beanComparator tag in the listElement tag for the column you want to sort on. I've also submitted a support ticket to Blackboard to let them know their documentation is incomplete in this area.
There are no comments for this entry.
[Add Comment]