/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.example.dwr.reverseajax; import java.util.LinkedList; import org.directwebremoting.Browser; import org.directwebremoting.ui.dwr.Util; /** * * @author wzw */ public class JavaChat { private final LinkedList<Message> messages = new LinkedList<Message>(); public void addMessage(String text) { if (text != null && text.trim().length() > 0) { messages.addFirst(new Message(text)); while (messages.size() > 10) { messages.removeLast(); } } // Clear the input box in the browser that kicked off this page only Util.setValue("text", ""); // For all the browsers on the current page: Browser.withCurrentPage(new Runnable() { public void run() { // Clear the list and add in the new set of messages Util.removeAllOptions("chatlog"); Util.addOptions("chatlog", messages, "text"); } }); } }