A new Lift Chat App screencast November 12, 2010
Enjoy: Screencast video
The HTML Template:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type" /><title>Home</title>
</head><body class="lift:content_id=main"><div id="main" class="lift:surround?with=default;at=content"><h2>Welcome to your project!</h2>This is my chat app, baby<br /><ul class="lift:comet?type=Chat"><li>Chat Line 1</li><li class="clearable">Chat Line 2</li><li class="clearable">Chat line 3<br /></li></ul><form action="/" class="lift:form.ajax"><input id="chat_in" class="lift:ChatIn" name="foo" /><br /><input value="say something" type="submit" /></form><br /><p> <span class="lift:helloWorld.howdy"> Welcome to your Lift app at <span id="time">Time goes here</span> </span> </p></div>
</body></html>
The Chat.scala file:
package codepackage comet
import net.liftweb._import http._import actor._import util._import Helpers._
object ChatServer extends LiftActor with ListenerManager {private var msgs = Vector("Welcome")
def createUpdate = msgs
override def lowPriority = {case s: String => msgs :+= s; updateListeners()}}
class Chat extends CometActor with CometListener {private var msgs: Vector[String] = Vector()
def registerWith = ChatServer
override def lowPriority = {case v: Vector[String] => msgs = v; reRender()}
def render = "li *" #> msgs & ClearClearable}
And the ChatIn.scala snippet:
package codepackage snippet
import net.liftweb._import http._import js._import JsCmds._import JE._
import comet.ChatServer
object ChatIn {def render = SHtml.onSubmit(s => {ChatServer ! sSetValById("chat_in", "")})}