GeLiftete Web-Applikation mit Scala
                                JAX 2009



                              Tobias Joch
...
Scala
Lift
  Grundlagen
    Architektur Überblick
    Module
    Template Verarbeitung
    Tags und Snippets
    Head Merg...
3
Scala = SCAlable LAnguage




                            4
Scala = SCAlable LAnguage
wächst mit den Bedürfnissen der User
kleine Skripte bis hin zu großen und komplexen
Systemen
Mul...
Wurzeln reichen zurück in das Jahr 1995
Philip Wadler und Martin Odersky
  Funktionale Programmiersprachen für die JVM
   ...
Ziel von Scala:
Das Beste aus beiden Welten (OO und FP)
  Statisch typisiert + Typinferenz
  Funktionen höherer Ordnung
  ...
Einige reservierte Schlüsselwörter in Scala
  class, case class, object
  new
  with
  extends
  abstract
  sealed
  trait...
in Action ;)




               8
Scala Shell
  Interactive Ruby Shell (IRB)
  ./scala
  Optimal für schnelle Tests




                                 9
Scala Shell
  Interactive Ruby Shell (IRB)
  ./scala
  Optimal für schnelle Tests




                                 9
Scala Shell
  Interactive Ruby Shell (IRB)
  ./scala
  Optimal für schnelle Tests




                                 9
Imperative vs. funktionale Programmierung (I)
 public class Example1 {
 	 public static void main(String[] args) {
 	 	 fo...
Imperative vs. funktionale Programmierung (I)
 public class Example1 {
 	 public static void main(String[] args) {
 	 	 fo...
Imperative vs. funktionale Programmierung (II)
  public class Example2 {
  	 public static void main(String[] args) {
  	 ...
Imperative vs. funktionale Programmierung (II)
  public class Example2 {
  	 public static void main(String[] args) {
  	 ...
Imperative vs. funktionale Programmierung (III)
  public class Example3 {
  	   public static void main(String[] args) {
 ...
Imperative vs. funktionale Programmierung (III)
  public class Example3 {
  	   public static void main(String[] args) {
 ...
Grundlagen
             13
David Pollak
  Gründer von Lift
  Kommerzielle Softwareentwicklung seit 1977
  Web-Applikationen seit 1996
15. Februar 200...
„Best of all“
Scala als zugrundeliegende Sprache
  nativer XML-Support (XHTML nativ innerhalb von Snippets!)
  Scala Actor...
Weitere Eigenschaften / Ziele von Lift
  Sicherheit
     XSS, replay Attacken, Parameter tampering
  Wartbarkeit
  Skalier...
„View First“ Design-Prinzip
     Templates enthalten keinen Code
     Pures XHTML
     Können mit Standard Design-Werkzeug...
Architektur Überblick
                        18
Lift-Framework




                 19
Lift-Framework




                 Scala Framework
                                   19
Lift-Framework




                  Lift-Framework

                 Scala Framework
                                   19
Lift-Framework




                 Lift Core
                    Lift-Framework

                  Scala Framework
      ...
LiftSession

                                                               LiftRules

                                   ...
LiftSession

                                                               LiftRules


                                  ...
Lift-Framework

              Mapper                               Record                                     Testkit
    ...
Lift-Framework

              Mapper                               Record                                     Testkit
    ...
Lift-Framework
                                                                                                           ...
Grobe Architektur einer Lift-Applikation




                                           20
Grobe Architektur einer Lift-Applikation




                       Java Virtual Machine
                                 ...
Grobe Architektur einer Lift-Applikation




                 Servlet Container (e.g. Jetty or Tomcat)

                  ...
Grobe Architektur einer Lift-Applikation




                                   Lift Framework




                 Servle...
Grobe Architektur einer Lift-Applikation
                                      Templates




                             ...
Grobe Architektur einer Lift-Applikation
                                      Templates



                              ...
Grobe Architektur einer Lift-Applikation
                                      Templates



                              ...
Grobe Architektur einer Lift-Applikation
                                        Templates



                            ...
Grobe Architektur einer Lift-Applikation
                                        Templates



                            ...
Grobe Architektur einer Lift-Applikation
                                                   Templates



                 ...
Grobe Architektur einer Lift-Applikation
                                                           Templates



         ...
Grobe Architektur einer Lift-Applikation
                                                           Templates



         ...
Grober Ablauf einer Anfragenbearbeitung




Request   URL rewrite              custom dispatch          Template          ...
Grober Ablauf einer Anfragenbearbeitung

                                                                       Template

...
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema




                                          22
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema

<path>[_<language, optional>][.<suffix>]




 ...
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema

<path>[_<language, optional>][.<suffix>]

Lift...
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema

<path>[_<language, optional>][.<suffix>]

Lift...
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema

<path>[_<language, optional>][.<suffix>]

Lift...
Template




Template Verarbeitung
  Request Mapping nach folgendem Schema

<path>[_<language, optional>][.<suffix>]

Lift...
Template




           23
Template




Templates = Content + Tags + Snippets




                                        23
Template




Templates = Content + Tags + Snippets
Tags = Lift spezifische Funktionen
  surround
  bind
  embed
  comet
  ...
Template




Templates = Content + Tags + Snippets
Tags = Lift spezifische Funktionen
  surround
  bind
  embed
  comet
  ...
›
                          Template




    Template Verarbeitung von Außen nach Innen




                              ...
›
                                    Template




    Template Verarbeitung von Außen nach Innen
/index.html

        <li...
›
                                    Template




    Template Verarbeitung von Außen nach Innen
/index.html

        <li...
›
                                    Template




    Template Verarbeitung von Außen nach Innen
/index.html

        <li...
Template




Head Merge




                        25
Template




  Head Merge
/index.html

   <lift:surround with=quot;defaultquot; at=quot;contentquot;>
      <head><script ...
Template




  Head Merge
/index.html

   <lift:surround with=quot;defaultquot; at=quot;contentquot;>
      <head><script ...
Template




  Head Merge
/index.html

   <lift:surround with=quot;defaultquot; at=quot;contentquot;>
      <head><script ...
Scopes
  S
  Stateful Snippet
  RequestVar
  SessionVar
  Scala Object (Singleton)




                             26
Internationalisierung / I18n
   java.util.Locale
   java.util.ResourceBundle
      LiftRules.resourceNames
Ermittlung der ...
Persistenz in Lift
  Mapper
  Record
  JPA
  JDO
  Hibernate
  ...
Lift selbst ist Persistenz agnostisch



              ...
AJAX in Lift
    SHtml
        ajaxButton
        ajaxText
        ajaxCheckbox
        ...


def render(in: NodeSeq): Nod...
in Action ;)
               30
Entwicklungsumgebung
  Java (>= 5)
  Maven (>= 2.0.9)
  Web-Container (Jetty, Tomcat, ...)
Optional, aber nützlich
  JavaR...
Projekt anlegen




                  32
Projekt anlegen
$mvn archetype:generate -U
 -DarchetypeGroupId=net.liftweb
 -DarchetypeArtifactId=lift-archetype-basic
 -D...
Projekt anlegen
$mvn archetype:generate -U
 -DarchetypeGroupId=net.liftweb
 -DarchetypeArtifactId=lift-archetype-basic
 -D...
Projektlayout




                33
Projektlayout




                33
Projektlayout




                33
Ausführen




            34
Ausführen

$mvn jetty:run




                 34
Ausführen

$mvn jetty:run




                 34
index.html




             35
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
index.html
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
	   	 <h2>Welcome to your project!</h2>
	   	 <...
default.html




               36
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
default.html
    <div class=quot;containerquot;>
      <div class=quot;column span-12 lastquot; style=quot;text-align: rig...
Boot.scala




             37
Boot.scala
     def boot {
         if (!DB.jndiJdbcConnAvailable_?)
           DB.defineConnectionManager(DefaultConnecti...
Rekursive Template Komposition




                                 38
Rekursive Template Komposition

class HelloWorld {
    def howdy = <span>Welcome to lift-demo at
                      {ne...
Rekursive Template Komposition

class HelloWorld {
    def howdy = <span>Welcome to lift-demo at
                      {ne...
Rekursive Template Komposition

class HelloWorld {
    def howdy = <span>Welcome to lift-demo at
                      {ne...
Rekursive Template Komposition

class HelloWorld {
    def howdy = <span>Welcome to lift-demo at
                      {ne...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare
    <lift:surround with=quot;defaultquot; at=quot;contentquot;>
       <h2>Very first form example:</h2>
       ...
Formulare




            40
Formulare




            40
Formulare




JAX 2009!
INFO - Service request (POST) /veryFirstForm took 61 Milliseconds

                               ...
Formulare




JAX 2009!
INFO - Service request (POST) /veryFirstForm took 61 Milliseconds

                               ...
more in Action ;)
                    41
Beispiel-Applikation(en)
  Scala Actors / Comet
  Modelle / OR-Mapping
  SiteMap
  Messages
  ...




                    ...
Beispiel-Applikation(en)
  Scala Actors / Comet
  Modelle / OR-Mapping
  SiteMap
  Messages
  ...


              Demo !
 ...
Zusammenfassung
                  43
44
Pro
  Sehr schicke Sprachfeatures
  „Best of all“ Prinzip
  Junge und dynamische Community
  Sehr gut für interaktive Webb...
Pro
  Sehr schicke Sprachfeatures
  „Best of all“ Prinzip
  Junge und dynamische Community
  Sehr gut für interaktive Webb...
Aktuell Roadmap 1.1 (Auszug der Lift Newsgroup)
   Improved documentation: better VScalaDoc coverage as well as better tut...
Ressourcen im Netz
  Scala
     http://scala-lang.org
  Lift
     http://liftweb.net/
     http://liftweb.net/docs/getting...
Exploring Lift
      Mail 2009, oder LyX Version!
      Derek Chen-Becker,
      Tyler Weir, Marius Danciu
Beginning Scala...
Fragen & Antworten



                        Tobias Joch
                        System Architecture
                    ...
Vielen Dank! ;)



                        Tobias Joch
                        System Architecture
                       ...
Upcoming SlideShare
Loading in …5
×

GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

1,343 views

Published on

Webframeworks für Java müssen nicht zwangsläufig in Java geschrieben sein. Neben prominenten Vertretern wie Grails oder JRuby entstehen weitere, wie z.B. das erst kürzlich in der Version 1.0 erschiene Framework Lift. Lift ist in der funktionalen und objektorientierten Programmiersprache Scala geschrieben und lässt sich nahtlos in bestehende Java-Anwendungen integrieren. Innerhalb dieses Vortrags wird Lift anhand einer Beispielanwendung vorgestellt.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,343
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

  1. 1. GeLiftete Web-Applikation mit Scala JAX 2009 Tobias Joch inovex GmbH Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.
  2. 2. Scala Lift Grundlagen Architektur Überblick Module Template Verarbeitung Tags und Snippets Head Merge Scopes I18n Persistenz AJAX in Action Fazit / Ausblick / weiterführende Informationen 2
  3. 3. 3
  4. 4. Scala = SCAlable LAnguage 4
  5. 5. Scala = SCAlable LAnguage wächst mit den Bedürfnissen der User kleine Skripte bis hin zu großen und komplexen Systemen Multiparadigmensprache verbindet objektorientierte (imperative) und funktionale Programmierung pragmatisch, typsicher, strikt objektorientiert interoperabel mit Standard Plattformen (Java, .NET) 4
  6. 6. Wurzeln reichen zurück in das Jahr 1995 Philip Wadler und Martin Odersky Funktionale Programmiersprachen für die JVM Pizza GJ (Generic Language Extension für Java) javac Java Generics 1999 verfolgte Martin Odersky das Ziel funktionale mit OO Programmierung zu kombinieren Funnel Scala *2001, 2003 erstes Public Release, 2006 Version 2.0, aktuell 2.7.4 RC1 5
  7. 7. Ziel von Scala: Das Beste aus beiden Welten (OO und FP) Statisch typisiert + Typinferenz Funktionen höherer Ordnung Traits, Mixin-Komposition Option-Klasse (None und Some vs. null) Pattern Matching Algebraische Typen Native XML-Unterstützung inkl. XPath Unterstützung (Bibliothek) Actor Model Currying Anonyme Funktionen Parametrische Polymorphie 6
  8. 8. Einige reservierte Schlüsselwörter in Scala class, case class, object new with extends abstract sealed trait def, var, val override match, case 7
  9. 9. in Action ;) 8
  10. 10. Scala Shell Interactive Ruby Shell (IRB) ./scala Optimal für schnelle Tests 9
  11. 11. Scala Shell Interactive Ruby Shell (IRB) ./scala Optimal für schnelle Tests 9
  12. 12. Scala Shell Interactive Ruby Shell (IRB) ./scala Optimal für schnelle Tests 9
  13. 13. Imperative vs. funktionale Programmierung (I) public class Example1 { public static void main(String[] args) { for (String arg : args) { System.out.println(arg); } } } 10
  14. 14. Imperative vs. funktionale Programmierung (I) public class Example1 { public static void main(String[] args) { for (String arg : args) { System.out.println(arg); } } } object Example1 { def main(args: Array[String]) { args.foreach(println) } } 10
  15. 15. Imperative vs. funktionale Programmierung (II) public class Example2 { public static void main(String[] args) { for (String arg : args) { if (arg.startsWith(quot;JAX09quot;)) { System.out.println(arg); } } } } 11
  16. 16. Imperative vs. funktionale Programmierung (II) public class Example2 { public static void main(String[] args) { for (String arg : args) { if (arg.startsWith(quot;JAX09quot;)) { System.out.println(arg); } } } } object Example2 { def main(args: Array[String]) { args.filter(_.startsWith(quot;JAX09quot;)).foreach(println) } } 11
  17. 17. Imperative vs. funktionale Programmierung (III) public class Example3 { public static void main(String[] args) { boolean exists = false; for (String arg : args) { if (arg.startsWith(quot;JAX09quot;)) { exists = true; break; } } System.out.print(exists); } } 12
  18. 18. Imperative vs. funktionale Programmierung (III) public class Example3 { public static void main(String[] args) { boolean exists = false; for (String arg : args) { if (arg.startsWith(quot;JAX09quot;)) { exists = true; break; } } System.out.print(exists); } } object Example3 { def main(args: Array[String]) { print(args.exists(_.startsWith(quot;JAX09quot;))) } } 12
  19. 19. Grundlagen 13
  20. 20. David Pollak Gründer von Lift Kommerzielle Softwareentwicklung seit 1977 Web-Applikationen seit 1996 15. Februar 2007: Initial Import (GitHub) in der Version 0.1.0 Gründung von Lift als OS Projekt in 2007 26. Februar 2009: Lift 1.0 Aktuelles Lift-Team besteht aus 13 Comitter Aktive Community http://groups.google.com/group/liftweb 14
  21. 21. „Best of all“ Scala als zugrundeliegende Sprache nativer XML-Support (XHTML nativ innerhalb von Snippets!) Scala Actors für mächtige Comet-Anwendungen fein granulare Sessions und Security (Seaside) schnelles Projektsetup durch „convention over configuration“ + geringe Turnaround-Zeiten (Rails) Django's quot;more than just CRUD is includedquot; Designer freundliche Templates (Wicket / Lift View First) Offen für die Nutzung von zahlreichen OSS-Bibliotheken (Java) Etablierte Deployment-Prozesse (JEE / Java) 15
  22. 22. Weitere Eigenschaften / Ziele von Lift Sicherheit XSS, replay Attacken, Parameter tampering Wartbarkeit Skalierbarkeit Performance Hohe Produktivität Einfach Convention over configuration DRY 16
  23. 23. „View First“ Design-Prinzip Templates enthalten keinen Code Pures XHTML Können mit Standard Design-Werkzeugen bearbeitet werden Frontend ist ohne Scala-Kenntnisse von einem Designer realisierbar <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> 17
  24. 24. Architektur Überblick 18
  25. 25. Lift-Framework 19
  26. 26. Lift-Framework Scala Framework 19
  27. 27. Lift-Framework Lift-Framework Scala Framework 19
  28. 28. Lift-Framework Lift Core Lift-Framework Scala Framework 19
  29. 29. LiftSession LiftRules LiftResponse Lift-Framework S SHtml JS API Lift Core Lift Webkit SiteMap Menu, Msgs, Lift-Framework Scala Framework CSS HTTP Auth Comet 19
  30. 30. LiftSession LiftRules Mapper LiftResponse Lift-Framework S SHtml Record JS API Lift Core Lift Webkit SiteMap Menu, Msgs, Lift-Framework Scala Framework CSS HTTP Auth Comet 19
  31. 31. Lift-Framework Mapper Record Testkit LiftResponse Menu, Msgs, LiftSession HTTP Auth LiftRules SiteMap JS API SHtml Comet CSS S Lift Webkit Lift Core Lift-Framework Scala Framework 19
  32. 32. Lift-Framework Mapper Record Testkit LiftResponse Menu, Msgs, LiftSession HTTP Auth LiftRules SiteMap JS API SHtml Comet CSS S Lift Webkit Lift Util Lift Core Lift-Framework Scala Framework 19
  33. 33. Lift-Framework Lift XMPP Mapper Record Testkit Lift Facebook LiftResponse Menu, Msgs, LiftSession HTTP Auth Lift Widgets LiftRules SiteMap JS API SHtml Comet CSS S Lift OpenId Lift OAuth Lift Webkit Lift Paypal Lift Util Lift AMQP Lift Core Lift-Framework Scala Framework 19
  34. 34. Grobe Architektur einer Lift-Applikation 20
  35. 35. Grobe Architektur einer Lift-Applikation Java Virtual Machine 20
  36. 36. Grobe Architektur einer Lift-Applikation Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  37. 37. Grobe Architektur einer Lift-Applikation Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  38. 38. Grobe Architektur einer Lift-Applikation Templates Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  39. 39. Grobe Architektur einer Lift-Applikation Templates Snippets Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  40. 40. Grobe Architektur einer Lift-Applikation Templates Snippets Views Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  41. 41. Grobe Architektur einer Lift-Applikation Templates Snippets Views Boot.scala (LiftRules etc,) Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  42. 42. Grobe Architektur einer Lift-Applikation Templates Snippets Model Views Boot.scala (LiftRules etc,) Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  43. 43. Grobe Architektur einer Lift-Applikation Templates Snippets Model LiftFilter Views Boot.scala (LiftRules etc,) Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  44. 44. Grobe Architektur einer Lift-Applikation Templates Snippets LiftServlet Model LiftFilter Views Boot.scala (LiftRules etc,) Lift Framework Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  45. 45. Grobe Architektur einer Lift-Applikation Templates Snippets LiftServlet Model LiftFilter Views Boot.scala (LiftRules etc,) Lift Framework DefaultServlet Servlet Container (e.g. Jetty or Tomcat) Java Virtual Machine 20
  46. 46. Grober Ablauf einer Anfragenbearbeitung Request URL rewrite custom dispatch Template View Response Response Response Response 21
  47. 47. Grober Ablauf einer Anfragenbearbeitung Template Request URL rewrite custom dispatch View Response Response Response Response 21
  48. 48. Template Template Verarbeitung Request Mapping nach folgendem Schema 22
  49. 49. Template Template Verarbeitung Request Mapping nach folgendem Schema <path>[_<language, optional>][.<suffix>] 22
  50. 50. Template Template Verarbeitung Request Mapping nach folgendem Schema <path>[_<language, optional>][.<suffix>] Lift wählt die passende Sprache und Endung 22
  51. 51. Template Template Verarbeitung Request Mapping nach folgendem Schema <path>[_<language, optional>][.<suffix>] Lift wählt die passende Sprache und Endung Links ohne Sprache und Endung angeben 22
  52. 52. Template Template Verarbeitung Request Mapping nach folgendem Schema <path>[_<language, optional>][.<suffix>] Lift wählt die passende Sprache und Endung Links ohne Sprache und Endung angeben Lift versteckt Templates und Ressourcen in Verzeichnissen welche als Endung -hidden im Namen tragen 22
  53. 53. Template Template Verarbeitung Request Mapping nach folgendem Schema <path>[_<language, optional>][.<suffix>] Lift wählt die passende Sprache und Endung Links ohne Sprache und Endung angeben Lift versteckt Templates und Ressourcen in Verzeichnissen welche als Endung -hidden im Namen tragen 22
  54. 54. Template 23
  55. 55. Template Templates = Content + Tags + Snippets 23
  56. 56. Template Templates = Content + Tags + Snippets Tags = Lift spezifische Funktionen surround bind embed comet loc 23
  57. 57. Template Templates = Content + Tags + Snippets Tags = Lift spezifische Funktionen surround bind embed comet loc Snippets vergleichbar mit Taglibs <lift:snippet type=Jax:render /> <lift:Jax.render /> <lift:Jax /> 23
  58. 58. › Template Template Verarbeitung von Außen nach Innen 24
  59. 59. › Template Template Verarbeitung von Außen nach Innen /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround> 24
  60. 60. › Template Template Verarbeitung von Außen nach Innen /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround> /templates-hidden/default.html <html xmlns=quot;...quot; xmlns:lift=quot;http://liftweb.net/quot;> <head>...</head> <body> ... <lift:bind name=quot;contentquot; /> </body> </html> 24
  61. 61. › Template Template Verarbeitung von Außen nach Innen /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround> /templates-hidden/default.html <html xmlns=quot;...quot; xmlns:lift=quot;http://liftweb.net/quot;> <head>...</head> <body> ... <lift:bind name=quot;contentquot; /> </body> </html> Ausführung von HelloWorld#howdy 24
  62. 62. Template Head Merge 25
  63. 63. Template Head Merge /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <head><script type=quot;text/javascriptquot;>...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> 25
  64. 64. Template Head Merge /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <head><script type=quot;text/javascriptquot;>...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> /templates-hidden/default.html <html xmlns=quot;...quot; xmlns:lift=quot;http://liftweb.net/quot;> <head>...</head> <body> ... <lift:bind name=quot;contentquot; /> </body> </html> 25
  65. 65. Template Head Merge /index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <head><script type=quot;text/javascriptquot;>...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> /templates-hidden/default.html <html xmlns=quot;...quot; xmlns:lift=quot;http://liftweb.net/quot;> <head>...</head> <body> ... <lift:bind name=quot;contentquot; /> </body> </html> 25
  66. 66. Scopes S Stateful Snippet RequestVar SessionVar Scala Object (Singleton) 26
  67. 67. Internationalisierung / I18n java.util.Locale java.util.ResourceBundle LiftRules.resourceNames Ermittlung der aktuellen Sprache LiftRules.localeCalculator Request-Header Fallback: Locale.getDefault() Snippets S.? Templates <lift:loc locid=quot;liftquot;>Aufzug</lift:loc> <lift:loc>lift</lift:loc> 27
  68. 68. Persistenz in Lift Mapper Record JPA JDO Hibernate ... Lift selbst ist Persistenz agnostisch 28
  69. 69. AJAX in Lift SHtml ajaxButton ajaxText ajaxCheckbox ... def render(in: NodeSeq): NodeSeq = SHtml.ajaxButton(quot;Click me ;)quot;, () => { println(quot;Yes, thanks!quot;) JsCmds.SetHtml(quot;click-divquot;, Text(quot;Yes, thanks!quot;)) }) 29
  70. 70. in Action ;) 30
  71. 71. Entwicklungsumgebung Java (>= 5) Maven (>= 2.0.9) Web-Container (Jetty, Tomcat, ...) Optional, aber nützlich JavaRebel (JVM Plugin / Java Agent) IDE mit Scala Support / Plugin (Eclipse, IDEA, Netbeans, ...) http://www.scala-lang.org/scala-eclipse-plugin 31
  72. 72. Projekt anlegen 32
  73. 73. Projekt anlegen $mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=1.0 -DgroupId=de.inovex.jax2009.lift -DartifactId=lift-demo 32
  74. 74. Projekt anlegen $mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=1.0 -DgroupId=de.inovex.jax2009.lift -DartifactId=lift-demo Import in Eclipse vorbereiten $cd lift-demo && mvn eclipse:eclipse 32
  75. 75. Projektlayout 33
  76. 76. Projektlayout 33
  77. 77. Projektlayout 33
  78. 78. Ausführen 34
  79. 79. Ausführen $mvn jetty:run 34
  80. 80. Ausführen $mvn jetty:run 34
  81. 81. index.html 35
  82. 82. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> 35
  83. 83. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala 35
  84. 84. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  85. 85. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  86. 86. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  87. 87. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  88. 88. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  89. 89. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  90. 90. index.html <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround> HelloWorld.scala import java.util.Date class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> } 35
  91. 91. default.html 36
  92. 92. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  93. 93. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  94. 94. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  95. 95. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  96. 96. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  97. 97. default.html <div class=quot;containerquot;> <div class=quot;column span-12 lastquot; style=quot;text-align: rightquot;> <h1 class=quot;altquot;>lift-demo <img id=quot;ajax-loaderquot; style=quot;display:none; margin-bottom: 0px; margin-left: 5pxquot; src=quot;/images/ajax-loader.gifquot;/></h1> </div> <hr/> <div class=quot;column span-6 colborder sidebarquot;> <hr class=quot;spacequot; /> <lift:Menu.builder /> <div> <lift:snippet type=quot;msgsquot;/> <hr class=quot;spacequot; /> </div> </div> <div class=quot;column span-17 lastquot;> <lift:bind name=quot;contentquot; /> </div> <hr /> <div class=quot;column span-23 lastquot; style=quot;text-align: centerquot;> <h4 class=quot;altquot;> <a href=quot;http://liftweb.netquot;><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36
  98. 98. Boot.scala 37
  99. 99. Boot.scala def boot { if (!DB.jndiJdbcConnAvailable_?) DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor) // where to search snippet LiftRules.addToPackages(quot;de.inovex.jax2009.liftquot;) // create or update the database schema Schemifier.schemify(true, Log.infoF _, User) // build site map val entries = Menu(Loc(quot;Homequot;, List(quot;indexquot;), quot;Homequot;)) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*)) // Show the spinny image when an Ajax call starts LiftRules.ajaxStart = Full(() => LiftRules.jsArtifacts.show(quot;ajax-loaderquot;).cmd) // Make the spinny image go away when it ends LiftRules.ajaxEnd = Full(() => LiftRules.jsArtifacts.hide(quot;ajax-loaderquot;).cmd) // force the request to be UTF-8 LiftRules.early.append(makeUtf8) S.addAround(DB.buildLoanWrapper) 37 }
  100. 100. Rekursive Template Komposition 38
  101. 101. Rekursive Template Komposition class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date} at <lift:helloWorld.howdy2 /></span> def howdy2 = <span>JAX 2009!</span> } 38
  102. 102. Rekursive Template Komposition class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date} at <lift:helloWorld.howdy2 /></span> def howdy2 = <span>JAX 2009!</span> } 38
  103. 103. Rekursive Template Komposition class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date} at <lift:helloWorld.howdy2 /></span> def howdy2 = <span>JAX 2009!</span> } 38
  104. 104. Rekursive Template Komposition class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date} at <lift:helloWorld.howdy2 /></span> def howdy2 = <span>JAX 2009!</span> } 38
  105. 105. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> 39
  106. 106. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } 39
  107. 107. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } 39
  108. 108. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } 39
  109. 109. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } 39
  110. 110. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } // in boot.scala: val entries = Menu(Loc(quot;Homequot;, List(quot;indexquot;), quot;Homequot;)) :: Menu(Loc(quot;form1quot;, List(quot;veryFirstFormquot;), quot;Examplequot;)) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*)) 39
  111. 111. Formulare <lift:surround with=quot;defaultquot; at=quot;contentquot;> <h2>Very first form example:</h2> <p> <lift:FormExample form=quot;POSTquot;> <f:name><input type=quot;textquot;/></f:name> <input type=quot;submitquot; value=quot;Postquot;/> </lift:FormExample> </p> </lift:surround> class FormExample { def render(xhtml: NodeSeq) = { bind(quot;fquot;, xhtml, quot;namequot; -> text(quot;quot;, println(_))) } } // in boot.scala: val entries = Menu(Loc(quot;Homequot;, List(quot;indexquot;), quot;Homequot;)) :: Menu(Loc(quot;form1quot;, List(quot;veryFirstFormquot;), quot;Examplequot;)) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*)) 39
  112. 112. Formulare 40
  113. 113. Formulare 40
  114. 114. Formulare JAX 2009! INFO - Service request (POST) /veryFirstForm took 61 Milliseconds 40
  115. 115. Formulare JAX 2009! INFO - Service request (POST) /veryFirstForm took 61 Milliseconds 40
  116. 116. more in Action ;) 41
  117. 117. Beispiel-Applikation(en) Scala Actors / Comet Modelle / OR-Mapping SiteMap Messages ... 42
  118. 118. Beispiel-Applikation(en) Scala Actors / Comet Modelle / OR-Mapping SiteMap Messages ... Demo ! 42
  119. 119. Zusammenfassung 43
  120. 120. 44
  121. 121. Pro Sehr schicke Sprachfeatures „Best of all“ Prinzip Junge und dynamische Community Sehr gut für interaktive Webbapplikationen („Real time web“) Native, volle JVM Geschwindigkeit 100% kompatibel mit Java Läuft auf Standard Servlet-Container (Jetty, Tomcat, ...) 44
  122. 122. Pro Sehr schicke Sprachfeatures „Best of all“ Prinzip Junge und dynamische Community Sehr gut für interaktive Webbapplikationen („Real time web“) Native, volle JVM Geschwindigkeit 100% kompatibel mit Java Läuft auf Standard Servlet-Container (Jetty, Tomcat, ...) Cons Steile Lernkurve Wenig Scala Ressourcen am Markt verfügbar (XING: 164) Noch weniger Lift Ressourcen verfügbar (XING: 3) Keine mir bekannten große Installationen aktuell vorzeigbar 44
  123. 123. Aktuell Roadmap 1.1 (Auszug der Lift Newsgroup) Improved documentation: better VScalaDoc coverage as well as better tutorial and cook-book documentation. Improved J2EE support including JTA and Portlets. Finish Record/Field code with backing store including JDBC, JPA and Goat Rodeo (what's Goat Rodeo? http://goatrodeo.org) Improved client-side JavaScript support and better JavaScript abstractions. Client/Server data synchronization (integrated with Record/Field) Improved support for REST. Improved performance including caching templates when running in production mode. OSGi support. Improved testing framework and better testing support when running in quot;testquot; mode. Implement Servlet 3.0 support. HTML 5 and Web Sockets support and integration with Kaazing's Web Sockets server. Also, sensing which browser is making the request and performing optimizations based on that browser's characteristics (specifically, Chrome and 45 Firefox 3.1 support)
  124. 124. Ressourcen im Netz Scala http://scala-lang.org Lift http://liftweb.net/ http://liftweb.net/docs/getting_started.html http://wiki.liftweb.net/ http://github.com/dpp/liftweb Lift Buch: „Exploring Lift“ http://groups.google.com/group/the-lift-book http://github.com/tjweir/liftbook/ 46
  125. 125. Exploring Lift Mail 2009, oder LyX Version! Derek Chen-Becker, Tyler Weir, Marius Danciu Beginning Scala Mail 2009 David Pollak Programming in Scala Martin Odersky, Lex Spoon, and Bill Venners ... 47
  126. 126. Fragen & Antworten Tobias Joch System Architecture Project Management inovex GmbH Karlsruher Straße 71 75179 Pforzheim 0173.3181 004 tobias.joch@inovex.de www.inovex.de Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.
  127. 127. Vielen Dank! ;) Tobias Joch System Architecture Project Management inovex GmbH Karlsruher Straße 71 75179 Pforzheim 0173.3181 004 tobias.joch@inovex.de www.inovex.de Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.

×