The doInitBody Method 1

The doInitBody() method of the outputChatMessages tag handler is very similar to that of the outputPathNames tag handler, which we discussed in Section 10.4.5, "The doInitBody Method." One major difference is that the BonForumStore method that is invoked by outputChatMessages is different, as shown here:

outputTable = new TreeMap( bonForumStore.outputForumChatMessages( command, attrl, «attr2, attr3, pageContext.getSession( ) ) );

This method returns a TreeMap object with nodeKey.aKey values as keys and chat messages (prefaced by the chat actor name) as the values. As you know, the keys are made from unique system clock times in milliseconds, so when the TreeMap keeps them sorted, it is effectively sorting them chronologically—important for displaying a page of chat messages. Because we want to display the messages, not the keys, there is another subtle difference in this doInitBody() method, compared to the one for the outputPathName tag. The iterator is on the TreeMap values, not its keys, as shown here: iterator = outputTable.values( ).iterator( );

Besides using a different message in case of an exception, the rest of the method is the same as for outputPathNames.The first (if any) value the iterator has available is put in the output scripting variable, where the upcoming tag body evaluation will find it as it evaluates the JSP expression used in the tag: <%= output %>.

0 0

Post a comment

  • Receive news updates via email from this site