Home > Articles > Programming > Java

Using the Struts Framework to Develop a Message Board--Part 6: Viewing the Bulletin Board

📄 Contents

  1. Using the Struts Framework to Develop a Message Board--Part 6: Viewing the Bulletin Board
  2. Creating the ShowHierarchy Action Class
  3. Creating the View JSP
  4. Running the Application
  • Print
  • + Share This
In this seven-part series, Java expert Maneesh Sahu explores how to use Apache Software Foundation's Struts framework to develop a Web-based message board. In part 6, he discussed viewing the bulletin board.
From the author of

The next step is to view the bulletin board containing the hierarchy of messages. To display the hierarchy, we use a data island. A data island is text that’s constructed by a bean—MessagesIsland, in this example. A JSP embeds the resultant text (created by the bean) to construct the output. An action class, ShowHierarchyAction, is responsible for initializing the MessagesIsland instance by setting the required format and setting the instance in the request scope for access by the JSP.

Creating the Data Island Bean MessagesIsland

The MessagesIsland bean traverses the message hierarchy recursively in order to generate the data island. The constructor takes a format string for displaying a message and the offset string for replies, as shown in Listing 1.

Listing 1 MessagesIsland.java—Recursively Creating the Data Island

import java.text.MessageFormat;

public class MessagesIsland {
    public String SPACE;
    public MessageFormat formatter;

    protected StringBuffer sb = new StringBuffer();
    protected OOMessage rootMessage;

public MessagesIsland(String format, String space) {
    formatter = new MessageFormat(format);
    SPACE = space;

public void setRootMessage(OOMessage message) {
    rootMessage = message;

public OOMessage getRootMessage() {
    return rootMessage;

public String getText() throws Exception {
    return sb.toString();

// Methods to display the messages
protected void printFromRoot(OOMessage rootMessage) throws Exception {
     if (rootMessage == null)
     for (int j = 0; j < rootMessage.getReplyCount(); j++) {
        printMessageHierarchy(rootMessage.getReplyAt(j), 0);

protected void printMessageHierarchy(OOMessage msg, int level) 
                               throws Exception {
     for (int j = 0; j < level; j++) {

     String[] args = { msg.getId(), msg.getSubject(), msg.getName(), 
     // print the replies recursively
     for (int i = 0; i < msg.getReplyCount(); i++) {
        printMessageHierarchy(msg.getReplyAt(i), (level+1));
  • + Share This
  • 🔖 Save To Your Account