Weitere ähnliche Inhalte Ähnlich wie London Scala UG - Lift:Getting started with Scala (20) Mehr von Skills Matter (20) Kürzlich hochgeladen (20) London Scala UG - Lift:Getting started with Scala4. Struts Play GWT Seam
Rails Spring MVC JSF WebObjects
Grails PHP Cocoon Seaside
Stripes JAX-RS Wicket Lift
5. Struts Play GWT Seam
Rails Spring MVC JSF WebObjects
Grails PHP Cocoon Seaside
Stripes JAX-RS Wicket Lift
Zero Plenty
Weirdness
7. Versions
1.0.3 Updated Jan 2010
2.0 M2 Released Feb 2010
both for Scala 2.7.7
10. $ find . -name lift* -depth 2 -type d
lift-base/lift-actor lift-modules/lift-paypal
lift-base/lift-common lift-modules/lift-testkit
lift-base/lift-json lift-modules/lift-textile
lift-base/lift-util lift-modules/lift-widgets
lift-base/lift-webkit lift-modules/lift-wizard
lift-modules/lift-xmpp
lift-modules/lift-amqp
lift-modules/lift-facebook lift-persistence/lift-couchdb
lift-modules/lift-imaging lift-persistence/lift-jpa
lift-modules/lift-jta lift-persistence/lift-mapper
lift-modules/lift-ldap lift-persistence/lift-record
lift-modules/lift-machine
lift-modules/lift-oauth
lift-modules/lift-openid
lift-modules/lift-osgi
11. Agenda
• Part I: View first
• Part II: Doing stuff quickly
• Part III: Ajax
• Part IV: Real time web
12. The time on this server is: Mon Mar 08 18:40:51 GMT 2010.
19. package com.myprojects.snippet
import scala.xml.NodeSeq
import net.liftweb.util.Helpers._
class Olympics {
case class Golds(country: String, medals: Int)
def results(xhtml: NodeSeq) = {
val vancouver = Golds("CAN", 14) :: Golds("GER", 10) ::
Golds("GBR", 1) :: Nil
// <table:rows> <r:country/> <r:golds/> </table:rows>
bind("table", xhtml,
! ! "rows" -> vancouver.flatMap( gold =>
bind("r", chooseTemplate("table", "rows", xhtml),
"country" -> gold.country,
"golds" -> gold.medals )
)
)
}
}
21. $ mvn archetype:generate
-DarchetypeCatalog=http://scala-tools.org/
Choose archetype:
1: http://scala-tools.org/ -> scala-archetype-simple (A simple scala project)
2: http://scala-tools.org/ -> lift-archetype-blank (A blank/empty liftweb project)
3: http://scala-tools.org/ -> lift-archetype-basic (A basic liftweb project (with DB, css, ...))
Choose a number: (1/2/3):
22. $ mvn archetype:generate
-DarchetypeGroupId=net.liftweb
-DarchetypeArtifactId=lift-archetype-blank
-DarchetypeVersion=2.0-M2
-DremoteRepositories=http://scala-tools.org/repo-releases
-DgroupId=com.example.proj
23. package com.brightonbloggers.admin.model
import net.liftweb.common._
import net.liftweb.util._
import net.liftweb.mapper._
import net.liftweb.http._
class Blog extends LongKeyedMapper[Blog] with IdPK {
def getSingleton = Blog
object title extends MappedString(this, 20)
object url extends MappedString(this, 100) {
override def validations = isUrl _ :: super.validations
}
def isUrl(u:String) = if (url startsWith "http")
! ! ! ! ! ! ! Nil
! ! ! ! ! ! else
! ! ! ! ! ! ! List(FieldError(url, S.?("field.url.error")))
}
object Blog extends Blog with LongKeyedMetaMapper[Blog] with CRUDify[Long,Blog]
{
}
25. import com.brightonbloggers.admin.model.Blog
import scala.xml._
import net.liftweb.common._
import net.liftweb.mapper._
import net.liftweb.http.SHtml._
import net.liftweb.http.js.JsCmds._
import net.liftweb.util.Helpers._
import net.liftweb.http.S._
class Blogs {
def list(xhtml: NodeSeq): NodeSeq = {
!
def add_new_blog(s: String) = {
Blog.create.url(s).title(s).save
SetHtml( "list", list(xhtml) )
}
bind("directory", xhtml,
! ! "entry" -> Blog.findAll().flatMap(
b => <li>{b.url}</li> ),
! ! "new_blog" -> ajaxText("", add_new_blog _)
)
}
}
26. package com.brightonbloggers.admin.snippet
import com.brightonbloggers.admin.model.Blog
import scala.xml._
import net.liftweb.common._
import net.liftweb.mapper._
import net.liftweb.http.SHtml._
import net.liftweb.http.js.JsCmds._
import net.liftweb.util.Helpers._
import net.liftweb.http.S._
class Blogs {
def list(xhtml: NodeSeq): NodeSeq = {
!
def add_new_blog(s: String) = {
Blog.create.url(s).title(s).save
SetHtml("list", list(xhtml) )
}
def update_blog(blog: Blog)(new_value: String) = {
blog.url(new_value).save
SetHtml("list", list(xhtml) )
}
def click_to_edit(blog: Blog) : NodeSeq =
!! swappable( <li>{blog.url}</li>,
!! ! ajaxText(blog.url, update_blog(blog) _ ) )
bind("directory", xhtml,
!! "entry" -> Blog.findAll().flatMap( click_to_edit _ ),
!! "new_blog" -> ajaxText("", add_new_blog _)
)
}
}
28. User Activity
Client Processing
Comet Event Bus
Event
Initialization
Data Push
Event Displa
y
Data Push
Displa
y
Event
Data Push
Event Displa
y
Data Push
Displa
y
Event
Data Push
Server-Side Processing
Displa
y
29. def list(xhtml: NodeSeq): NodeSeq = {
!
def countable(blog: Blog) : NodeSeq =
! <li>{link("/static/list",
() => { StatsServer ! blog },
Text(blog.url)) }</li>
bind("directory", xhtml,
! ! "entry" -> Blog.findAll().flatMap(countable _)
)
30. package com.brightonbloggers.admin.comet
import net.liftweb.http._
import net.liftweb.common._
import net.liftweb.util.Helpers._
import net.liftweb.http.js._
import net.liftweb.actor._
import net.liftweb.http.js.JsCmds._
import scala.xml._
object StatsServer extends LiftActor with ListenerManager {
var count = 0
override def lowPriority = {
case b =>
count = count + 1
updateListeners()
}
def createUpdate = count
}
// <lift:comet type=”StatsWatch” />
class StatsWatch extends CometActor with CometListenee {
def registerWith = StatsServer
override def render = <div id="total">0</div>
override def lowPriority = {
case count: Int =>
partialUpdate(SetHtml("total", Text(count.toString)))
}
}
31. Thank you.
• Lift book: http://groups.google.com/group/
the-lift-book
• Liftweb.net: Wiki, mailing list, getting started
guide
• Visit lsug.org, join the meetup.com group