Successfully reported this slideshow.

Scala & Lift (JEEConf 2012)

1

Share

Upcoming SlideShare
Java 9 Modularity in Action
Java 9 Modularity in Action
Loading in …3
×
1 of 33
1 of 33

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Scala & Lift (JEEConf 2012)

  1. 1. Elevate your webapps with Scala & Lift @Sander_Mak
  2. 2. About Coding at Writing Blog @ branchandbound.net Speaking
  3. 3. What should a webframework do?
  4. 4. Webframeworks should... Provide templating Show dynamic content Handle user input Abstract from request/response cycle? Be highly interactive? Preferably: concise, performant, secure
  5. 5. Webframeworks should... Provide templating Lift is view-first Templates pure HTML5 or XHTML Embed and surround to compose default.html with: <lift:bind name=”content” /> signup.html with: <lift:surround with=”default” name=”content”> <form> ... signup form ... </form> <lift:surround />
  6. 6. Webframeworks should... Show dynamic content Pure templates: no code in templates Problem?
  7. 7. Webframeworks should... Show dynamic content Pure templates: no code in templates Problem?
  8. 8. Webframeworks should... Show dynamic content Snippets transform DOM to DOM NodeSeq => NodeSeq Guarantee: well-formedness, sanitized Use {request, session, database} state
  9. 9. Webframeworks should... Show dynamic content Snippet View class IndexSnippet { .. surrounding html .. def date(in: NodeSeq): NodeSeq = <lift:indexSnippet.date> Helpers.bind("b", in, <div>Current date: "date" -> new Date()) <b:date> 10:00:00 1/1/2012 } </b:date> </div> </lift:indexSnippet.date>
  10. 10. Webframeworks should... Show dynamic content ‘Operators’ and implicit conversions: “date”.->(new Date()) results in a tuple: (“date”, new Date()) Snippet View class IndexSnippet { .. surrounding html .. def date(in: NodeSeq): NodeSeq = <lift:indexSnippet.date> Helpers.bind("b", in, <div>Current date: "date" -> new Date()) <b:date> 10:00:00 1/1/2012 } </b:date> </div> </lift:indexSnippet.date>
  11. 11. Webframeworks should... Show dynamic content Snippet (CSS binding) View class CssSnippet { .. surrounding html .. <div class="lift:cssSnippet.date"> def date: NodeSeq => NodeSeq = Current date: "#date" #> currentDate <span id="date">10:00:00 1/1/2012</span> } </div> .. surrounding html ..
  12. 12. Webframeworks should... Show dynamic content Constructs a function NodeSeq => NodeSeq Snippet (CSS binding) View class CssSnippet { .. surrounding html .. <div class="lift:cssSnippet.date"> def date: NodeSeq => NodeSeq = Current date: "#date" #> currentDate <span id="date">10:00:00 1/1/2012</span> } </div> .. surrounding html ..
  13. 13. Webframeworks should... Show dynamic content Implicit conversion from String to ToCssBindPromoter Snippet (CSS binding) View class CssSnippet { .. surrounding html .. <div class="lift:cssSnippet.date"> def date: NodeSeq => NodeSeq = Current date: "#date" #> currentDate <span id="date">10:00:00 1/1/2012</span> } </div> .. surrounding html ..
  14. 14. Webframeworks should... Show dynamic content With HTML5 may also be data-lift=”cssSnippet.date” Snippet (CSS binding) View class CssSnippet { .. surrounding html .. <div class="lift:cssSnippet.date"> def date: NodeSeq => NodeSeq = Current date: "#date" #> currentDate <span id="date">10:00:00 1/1/2012</span> } </div> .. surrounding html ..
  15. 15. Webframeworks should... Show dynamic content No MVC: MenuSnippet View <=> Snippet NewsSnippet Many <=> Many FormSnippet
  16. 16. Webframeworks should... Handle user input Add server-side behavior to DOM ... with snippets Behavior captured in closures ... managed by Lift, executed after submit Plain and Ajax requests unified Primarily stateful!
  17. 17. Webframeworks should... Handle user input Snippet View class FormSnippet { def nameForm = { .. surrounding html .. var name = "" <form method="POST" def processForm() = class="lift:FormSnippet.nameForm"> println(name) <input id="nameField" type="text"/> "#nameField" #> <input id="submitButton" type="submit"/> SHtml.text(name, name = _) </form> & "#submitButton" #> .. surrounding html .. SHtml.submit("Click", processForm) } }
  18. 18. Webframeworks should... Handle user input Method within method: Snippet View references name in outer scope class FormSnippet { def nameForm = { .. surrounding html .. var name = "" <form method="POST" def processForm() = class="lift:FormSnippet.nameForm"> println(name) <input id="nameField" type="text"/> "#nameField" #> <input id="submitButton" type="submit"/> SHtml.text(name, name = _) </form> & "#submitButton" #> .. surrounding html .. SHtml.submit("Click", processForm) } }
  19. 19. Webframeworks should... Handle user input Equivalent to: (inputName: String) => name = inputName Snippet View Closure in shorthand format class FormSnippet { def nameForm = { .. surrounding html .. var name = "" <form method="POST" def processForm() = class="lift:FormSnippet.nameForm"> println(name) <input id="nameField" type="text"/> "#nameField" #> <input id="submitButton" type="submit"/> SHtml.text(name, name = _) </form> & "#submitButton" #> .. surrounding html .. SHtml.submit("Click", processForm) } }
  20. 20. Webframeworks should... Handle user input Combine 2 CSS transforms into single aggregated transformation Snippet View def &(other: CssSel): CssSel class FormSnippet { def nameForm = { .. surrounding html .. var name = "" <form method="POST" def processForm() = class="lift:FormSnippet.nameForm"> println(name) <input id="nameField" type="text"/> "#nameField" #> <input id="submitButton" type="submit"/> SHtml.text(name, name = _) </form> & "#submitButton" #> .. surrounding html .. SHtml.submit("Click", processForm) } }
  21. 21. Webframeworks should... Handle user input SHtml components: powerful but low- level abstractions: LiftScreen Wizard Declarative Multipage wizards forms Backbutton Validation support Strongly typed ‘Conversations’
  22. 22. Webframeworks should...
  23. 23. Comet ‘Reverse Ajax’ or ‘server push’ Realtime webapps How to model this?
  24. 24. Comet ... with actors! Asynchronous Mailbox serializes processing Lightweight Event-driven execution Local state Behavior mailbox
  25. 25. Comet ... with actors! Asynchronous Mailbox serializes processing Lightweight Event-driven execution Local state Send message to actor: Behavior actor ! MyMessage(“payload”) mailbox
  26. 26. Comet Chat demo setup Actor ChatServer CometActor CometActor CometActor ChatClient ChatClient ChatClient ... Browser Browser Browser ...
  27. 27. Scala + Lift = Abstraction
  28. 28. Scala + Lift = Abstraction Wiring UI: Functional/reactive programming
  29. 29. Scala + Lift = Abstraction Other abstractions: Mapper (ORM) Record (NoSQL) REST Helper (sync/async) Javascript & JSON DSL
  30. 30. Lift vs Play Powertool vs Polished product
  31. 31. Who uses Lift?
  32. 32. Wrapping up Designer friendly, logic free views Concise; leverages Scala Comet/Ajax integration second to none Mature framework with great community Relatively steep learning curve Documentation slowly improving Stateful, but no session replication
  33. 33. Questions Code @ bit.ly/jeeconf-lift branchandbound.ne @Sander_Mak

Editor's Notes

  • \n
  • \n
  • \n
  • \n
  • Designer-friendly\n\nDemo master layout\n
  • \n
  • \n
  • \n
  • Show code: Boot class and IndexSnippet. Explain designer-friendly templating based on code. Start with date example, also table to show multiple lines of output\n
  • Show code: Boot class and IndexSnippet. Explain designer-friendly templating based on code. Start with date example, also table to show multiple lines of output\n
  • Show code: Boot class and IndexSnippet. Explain designer-friendly templating based on code. Start with date example, also table to show multiple lines of output\n
  • Show code: Boot class and IndexSnippet. Explain designer-friendly templating based on code. Start with date example, also table to show multiple lines of output\n
  • Show code: Boot class and IndexSnippet. Explain designer-friendly templating based on code. Start with date example, also table to show multiple lines of output\n
  • \n
  • \n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • Show NameSnippet, introduce S object (with notices), stateful part\n
  • First show Ajax autocomplete\n
  • \n
  • you can have millions of actors per JVM\n
  • you can have millions of actors per JVM\n
  • \n
  • \n
  • \n
  • Documentation, err msg/dev experience: Play better\nView-first vs MVC with code in templates + Servlet based vs. custom HTTP stack\nLift: security, more freedom (more rope to hang yourself), Play more handholding\nLift doesn&amp;#x2019;t give one true way\n
  • \n
  • \n
  • \n
  • ×