Scala & Lift
Sander Mak
What should a
webframework
do?
Webframeworks should
• Provide templating
• Show dynamic content
• Handle user input
• Abstract from request/response cycle?
• Be highly interactive?
  Preferably concise, performant and secure
Webframeworkstemplating
         Provide
                 should
• Lift is view-first
   • Pure XHTML or HTML5 templates
• Embed and surround to compose pages
                                    default.html
with:
                                    <lift:bind name=”content” />




    signup.html
with:
    <lift:surround with=”default”
        name=”content”>

        ... signup form ...

    <lift:surround />
Webframeworks should
         Show dynamic content

• Pure templates: no code in templates
                 Problem?
Snippets
Webframeworks should
         Show dynamic content

• Snippets transform DOM to DOM
  NodeSeq => NodeSeq
• Well-formed and sanitized transformation
• Use {request, session, database} state
Webframeworks should
          Show dynamic content

 • Snippets transform DOM to DOM
    NodeSeq => NodeSeq
 • Well-formed and sanitized transformation
 • Use {request, session, database} state
Not MVC:                              menu

/index.xhtml                          date

                                       content
Webframeworks should
          Handle user input

• Add server-side behavior to DOM nodes
  ... with snippets
• Behavior captured in closures
  ... which are executed after submit


• Lift unifies ajax and traditional request/
  response interaction, includes JavaScript DSL
Highly interactive
Comet
• ‘Reverse Ajax’: server push
• Realtime webapps
Actors
Actors
• Asynchronous
• Mailbox serializes messages        Mailbox

                                   Internal state

• Thread pooling executor
                                    Actor

                 actor ! Message
The demo
                Actor

                   ChatServer


CometActor      CometActor              CometActor


  ChatClient       ChatClient              ChatClient
                                  ...



    Browser             Browser              Browser
                                  ...
Scala + Lift =




       Abstraction
Wiring
• Functional/reactive programming
What else?

• Persistence layer - Mapper & Record
• REST support - Expose APIs for webapps
• Lift Modules - User contributed

Scala and Lift

  • 1.
  • 2.
  • 3.
    Webframeworks should • Providetemplating • Show dynamic content • Handle user input • Abstract from request/response cycle? • Be highly interactive? Preferably concise, performant and secure
  • 4.
    Webframeworkstemplating Provide should • Lift is view-first • Pure XHTML or HTML5 templates • Embed and surround to compose pages default.html
with: <lift:bind name=”content” /> signup.html
with: <lift:surround with=”default” name=”content”> ... signup form ... <lift:surround />
  • 5.
    Webframeworks should Show dynamic content • Pure templates: no code in templates Problem?
  • 6.
  • 7.
    Webframeworks should Show dynamic content • Snippets transform DOM to DOM NodeSeq => NodeSeq • Well-formed and sanitized transformation • Use {request, session, database} state
  • 8.
    Webframeworks should Show dynamic content • Snippets transform DOM to DOM NodeSeq => NodeSeq • Well-formed and sanitized transformation • Use {request, session, database} state Not MVC: menu /index.xhtml date content
  • 9.
    Webframeworks should Handle user input • Add server-side behavior to DOM nodes ... with snippets • Behavior captured in closures ... which are executed after submit • Lift unifies ajax and traditional request/ response interaction, includes JavaScript DSL
  • 11.
  • 12.
    Comet • ‘Reverse Ajax’:server push • Realtime webapps
  • 13.
  • 14.
    Actors • Asynchronous • Mailboxserializes messages Mailbox Internal state • Thread pooling executor Actor actor ! Message
  • 15.
    The demo Actor ChatServer CometActor CometActor CometActor ChatClient ChatClient ChatClient ... Browser Browser Browser ...
  • 17.
    Scala + Lift= Abstraction
  • 18.
  • 19.
    What else? • Persistencelayer - Mapper & Record • REST support - Expose APIs for webapps • Lift Modules - User contributed