| [ directory ] |
|
5.6 The Section PageListing 5.3 showed how the section page will be called from the list of available sections and how this page will be passed a sectionId as if a form had sent it. This means that it will be possible to use a bean and a jsp:setProperty to tell that bean which section was selected, just as was done in the section list to place an asterisk in front of the current section. If the section bean is designed to load up all the stories in a section when the sectionId property is set, all that is necessary to build the section page is to iterate the available articles with a c:forEach tag. That is exactly what Listing 5.7 does. Listing 5.7 The section page
<jsp:useBean
id="currentSection"
class="com.awl.jspbook.ch05.SectionBean"/>
<jsp:setProperty
name="currentSection"
property="sectionId"/>
<dl>
<c:forEach items="${currentSection.articles}"
var="article">
<dt><a href="<c:url value="article.jsp">
<c:param name="articleId"
value="${article.articleId}"/>
</c:url>"><c:out value="${article.headline}"/></a>
<dd><c:out value="${article.summary}"/>
</c:forEach>
</dl>
If this looks very similar to the section list from Listing 5.3, it should! They both do essentially the same thing; the only significant difference is that the items in this example are in a definition list instead of an unordered list. In particular, the c:url tag is used in both. Figure 5.3 shows how the section page looks in a browser. Figure 5.3. The JNT section page.
|
| [ directory ] |
|