Skip to main content
Kinetic Community

Exercise Three - add forms to the display

Overview

In this exercise we will continue to add to the categories.jsp file and the subCategory.jsp file.  We will display all of the forms, using the form name, that a category has; below the category name.  This is done by using the forms property on the bundleCategory object.  The forms property will retrieve an array of form objects that have been assigned to the category.  We will used a for loop to loop over the array and using the name property on the form object to display the form's name.

Activity

  1. Add an unordered list to the categories.jsp file that has a for each loop that will be used to display the form names.
<li>
  <ul>
    <c:forEach var="form" items="${category.forms}">
    
      <%-- Replace this with step 2 of exercise 3. Display form names using a list item element --%>
      
    </c:forEach>
  </ul>
</li>

Remember that the category variable references a bundleCategory object.  Another property on the bundleCategory object is the forms property which retrieves an array of form objects that are assigned to the category.  BundleCategory is a child class of the Category class.  When we look at a specific instance of one of these classes we are looking at an object.

  1. Display the form name.
<li>${text.escape(form.name)}</li>

Above a form object is assigned to the form variable.  A property on the form object is name.  The name property returns the name of the form as a string.  We use text.escape to escape any special characters that could be in the string that is returned from the name property. 

  1. Add an unordered list to the subCategory.jsp file that has a for each loop that will be used to display the form names. (make sure your in the subCategory.jsp for steps 3 and 4.)
<li>
  <ul>
    <c:forEach var="form" items="${subcategory.forms}">
    
      <%-- Replace this with step 4 or exercise 3. Display form names using a list item element --%>
      
    </c:forEach>
  </ul>
</li>

Remember that the subcategory variable references a bundleCategory object.  BundleCategory is a child class of the Category class and the subcategory variable is pointing at an instance of the bundleCategory.  The instance is an objet of the type bundleCategory which has a property called forms.  The forms property actually exists on the parent class Category.  When we pass a property from a parent class to a child class it is called property delegation.  Parent/Child relationships between classes and property delegation are common programming techniques that can looked up using the web.  The Parent/Child relationship also goes by the name extending classes.

  1. Display the form name.
<li>${text.escape(form.name)}</li>