Displaying a Posting
To display the content of a posting (plus a list of replies to the posting):
<c:if test="${!empty param.postingId}"> <forum:posting id="posting" postingId="${param.postingId}"/> </c:if> <c:if test="${!empty posting}"> <h2> You're viewing posting with ID ${posting.id} from forum with ID ${posting.forum.id} </h2> <p> <c:out escapeXml="false" value="${posting.body}"/> </p> <p> Created ${posting.creationDate} <c:if test="${posting.thread.id != posting.id}"> as a reply to <a href="${pageContext.request.requestURL}?postingId=${posting.thread.id}"> posting with ID ${posting.parent.id} </a> </c:if> <c:if test="${posting.thread.id == posting.id}"> (first posting on this thread) </c:if> </p> <c:if test="${posting.repliesCount > 0}"> <h3>Has ${posting.repliesCount} replies:</h3> <ul> <c:forEach var="reply" items="${posting.replies}"> <li> <a href="${reply.url}"> Posting ID ${reply.id}, created ${reply.creationDate} </a> </li> </c:forEach> </ul> </c:if> </c:if>
The most significant points in the above listing are highlighted and described below:
<forum:posting id="posting" postingId="${param.postingId}"/>
-
The
forum:posting
tag (see forum:posting) is used to create aPresentationPosting
bean (see PresentationPosting) calledposting
. <c:out escapeXml="false" value="${posting.body}"/>
-
This displays the content of the posting (returned from the
posting
bean's body property). <c:if test="${posting.thread.id != posting.id}">
and<c:if test="${posting.thread.id == posting.id}">
-
These tests check whether or not the posting is a root posting (that is, a thread). If a posting's thread ID is the same as its posting ID, then it is a root posting or thread, and not a reply to another posting.
<c:forEach var="reply" items="${posting.replies}">
-
This code cycles through the posting's replies, creating a new
PresentationPosting
bean calledreply
to represent each thread.