+ All Categories
Home > Technology > GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

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

Date post: 10-Nov-2014
Category:
Upload: vesparun
View: 2,195 times
Download: 2 times
Share this document with a friend
Description:
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.
127
GeLiftete Web-Applikation mit Scala JAX 2009 Tobias Joch inovex GmbH Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.
Transcript
Page 1: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

GeLiftete Web-Applikation mit Scala

JAX 2009

Tobias Jochinovex GmbH

Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.

Page 2: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

2

ScalaLift

GrundlagenArchitektur ÜberblickModuleTemplate VerarbeitungTags und SnippetsHead MergeScopesI18nPersistenzAJAX

in ActionFazit / Ausblick / weiterführende Informationen

Page 3: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

3

Page 4: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

4

Scala = SCAlable LAnguage

Page 5: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

4

wächst mit den Bedürfnissen der Userkleine Skripte bis hin zu großen und komplexen SystemenMultiparadigmensprache

verbindet objektorientierte (imperative) und funktionale Programmierung

pragmatisch, typsicher, strikt objektorientiertinteroperabel mit Standard Plattformen (Java, .NET)

Scala = SCAlable LAnguage

Page 6: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

5

Wurzeln reichen zurück in das Jahr 1995Philip Wadler und Martin Odersky

Funktionale Programmiersprachen für die JVMPizzaGJ (Generic Language Extension für Java)javacJava Generics

1999 verfolgte Martin Odersky das Ziel funktionale mit OO Programmierung zu kombinieren

FunnelScala

*2001, 2003 erstes Public Release, 2006 Version 2.0, aktuell 2.7.4 RC1

Page 7: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Ziel von Scala:Das Beste aus beiden Welten (OO und FP)

Statisch typisiert + TypinferenzFunktionen höherer OrdnungTraits, Mixin-KompositionOption-Klasse (None und Some vs. null)Pattern MatchingAlgebraische TypenNative XML-Unterstützung inkl. XPath Unterstützung (Bibliothek)Actor ModelCurryingAnonyme FunktionenParametrische Polymorphie 6

Page 8: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Einige reservierte Schlüsselwörter in Scalaclass, case class, objectnew withextends abstract sealedtraitdef, var, valoverridematch, case

7

Page 9: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

8

in Action ;)

Page 10: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Scala ShellInteractive Ruby Shell (IRB) ./scalaOptimal für schnelle Tests

9

Page 11: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Scala ShellInteractive Ruby Shell (IRB) ./scalaOptimal für schnelle Tests

9

Page 12: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Scala ShellInteractive Ruby Shell (IRB) ./scalaOptimal für schnelle Tests

9

Page 13: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

10

Imperative vs. funktionale Programmierung (I)

public class Example1 { public static void main(String[] args) { for (String arg : args) { System.out.println(arg); } }}

Page 14: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

10

Imperative vs. funktionale Programmierung (I)

object Example1 {def main(args: Array[String]) {

args.foreach(println)}

}

public class Example1 { public static void main(String[] args) { for (String arg : args) { System.out.println(arg); } }}

Page 15: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

11

Imperative vs. funktionale Programmierung (II)public class Example2 { public static void main(String[] args) { for (String arg : args) { if (arg.startsWith("JAX09")) { System.out.println(arg); } } }}

Page 16: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

11

Imperative vs. funktionale Programmierung (II)

object Example2 { def main(args: Array[String]) { args.filter(_.startsWith("JAX09")).foreach(println) }}

public class Example2 { public static void main(String[] args) { for (String arg : args) { if (arg.startsWith("JAX09")) { System.out.println(arg); } } }}

Page 17: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

12

Imperative vs. funktionale Programmierung (III)public class Example3 { public static void main(String[] args) { boolean exists = false; for (String arg : args) { if (arg.startsWith("JAX09")) { exists = true; break; } } System.out.print(exists); }}

Page 18: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

12

Imperative vs. funktionale Programmierung (III)

object Example3 { def main(args: Array[String]) { print(args.exists(_.startsWith("JAX09"))) }}

public class Example3 { public static void main(String[] args) { boolean exists = false; for (String arg : args) { if (arg.startsWith("JAX09")) { exists = true; break; } } System.out.print(exists); }}

Page 19: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

13

Grundlagen

Page 20: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

David PollakGründer von LiftKommerzielle Softwareentwicklung seit 1977Web-Applikationen seit 1996

15. Februar 2007:Initial Import (GitHub) in der Version 0.1.0Gründung von Lift als OS Projekt in 200726. Februar 2009:Lift 1.0Aktuelles Lift-Team besteht aus 13 ComitterAktive Community

http://groups.google.com/group/liftweb 14

Page 21: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

„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 "more than just CRUD is included"Designer freundliche Templates (Wicket / Lift View First)Offen für die Nutzung von zahlreichen OSS-Bibliotheken (Java)Etablierte Deployment-Prozesse (JEE / Java) 15

Page 22: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Weitere Eigenschaften / Ziele von LiftSicherheit

XSS, replay Attacken, Parameter tamperingWartbarkeitSkalierbarkeitPerformanceHohe ProduktivitätEinfachConvention over configurationDRY

16

Page 23: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

„View First“ Design-PrinzipTemplates enthalten keinen CodePures XHTMLKönnen mit Standard Design-Werkzeugen bearbeitet werdenFrontend ist ohne Scala-Kenntnisse von einem Designer realisierbar

17

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

Page 24: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

18

Architektur Überblick

Page 25: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19

Page 26: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Page 27: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Page 28: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Page 29: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Lift Webkit

Com

et

SH

tml

S

LiftR

ule

s

LiftS

essio

n

JS

AP

I

SiteM

ap

Menu, M

sgs,

CS

S

HT

TP

Auth

LiftR

esponse

Page 30: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Lift Webkit

Com

et

SH

tml

S

LiftR

ule

s

LiftS

essio

n

JS

AP

I

SiteM

ap

Menu, M

sgs,

CS

S

HT

TP

Auth

LiftR

esponse

Mapper Record

Page 31: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Lift Webkit

Com

et

SH

tml

S

LiftR

ule

s

LiftS

essio

n

JS

AP

I

SiteM

ap

Menu, M

sgs,

CS

S

HT

TP

Auth

LiftR

esponse

Mapper Record Testkit

Page 32: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Lift Webkit

Com

et

SH

tml

S

LiftR

ule

s

LiftS

essio

n

JS

AP

I

SiteM

ap

Menu, M

sgs,

CS

S

HT

TP

Auth

LiftR

esponse

Mapper Record Testkit

Lift Util

Page 33: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Lift-Framework

19Scala Framework

Lift-Framework

Lift Core

Lift Webkit

Com

et

SH

tml

S

LiftR

ule

s

LiftS

essio

n

JS

AP

I

SiteM

ap

Menu, M

sgs,

CS

S

HT

TP

Auth

LiftR

esponse

Mapper Record Testkit

Lift Util

Lift XMPP

Lift Facebook

Lift Widgets

Lift OpenId

Lift OAuth

Lift Paypal

Lift AMQP

Page 34: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Grobe Architektur einer Lift-Applikation

20

Page 35: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Page 36: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Page 37: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Lift Framework

Page 38: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Lift Framework

Page 39: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Snippets

Lift Framework

Page 40: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Lift Framework

Page 41: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Boot.scala (LiftRules etc,)

Lift Framework

Page 42: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Boot.scala (LiftRules etc,)

Model

Lift Framework

Page 43: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Boot.scala (LiftRules etc,)

LiftFilter Model

Lift Framework

Page 44: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Boot.scala (LiftRules etc,)

LiftServlet

LiftFilter Model

Lift Framework

Page 45: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Java Virtual Machine

Grobe Architektur einer Lift-Applikation

20

Servlet Container (e.g. Jetty or Tomcat)

Templates

Views

Snippets

Boot.scala (LiftRules etc,)

LiftServlet

LiftFilter Model

Lift Framework

DefaultServlet

Page 46: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Grober Ablauf einer Anfragenbearbeitung

21

Request URL rewrite View Responsecustom dispatch

Response

Response

ResponseTemplate

Page 47: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Grober Ablauf einer Anfragenbearbeitung

21

Request URL rewrite View Responsecustom dispatch

Response

Response

Response

Template

Page 48: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

Template

Page 49: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

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

Template

Page 50: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

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

Lift wählt die passende Sprache und Endung

Template

Page 51: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

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

Lift wählt die passende Sprache und EndungLinks ohne Sprache und Endung angeben

Template

Page 52: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

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

Lift wählt die passende Sprache und EndungLinks ohne Sprache und Endung angeben

Lift versteckt Templates und Ressourcen in Verzeichnissen welche als Endung -hidden im Namen tragen

Template

Page 53: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Template VerarbeitungRequest Mapping nach folgendem Schema

22

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

Lift wählt die passende Sprache und EndungLinks ohne Sprache und Endung angeben

Lift versteckt Templates und Ressourcen in Verzeichnissen welche als Endung -hidden im Namen tragen

Template

Page 54: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

23

Template

Page 55: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Templates = Content + Tags + Snippets

23

Template

Page 56: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Templates = Content + Tags + SnippetsTags = Lift spezifische Funktionen

surroundbindembedcometloc

23

Template

Page 57: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Templates = Content + Tags + SnippetsTags = Lift spezifische Funktionen

surroundbindembedcometloc

Snippetsvergleichbar mit Taglibs<lift:snippet type=Jax:render /> <lift:Jax.render /> <lift:Jax /> 23

Template

Page 58: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

24

Template Verarbeitung von Außen nach Innen

Template

Page 59: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

24

Template Verarbeitung von Außen nach Innen

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround>

/index.html

Template

Page 60: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

24

Template Verarbeitung von Außen nach Innen

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround>

/index.html

/templates-hidden/default.html

<html xmlns="..." xmlns:lift="http://liftweb.net/"> <head>...</head> <body>

...<lift:bind name="content" />

</body></html>

Template

Page 61: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

24

Template Verarbeitung von Außen nach Innen

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:HelloWorld.howdy /></p> </lift:surround>

/index.html

/templates-hidden/default.html

<html xmlns="..." xmlns:lift="http://liftweb.net/"> <head>...</head> <body>

...<lift:bind name="content" />

</body></html>

Ausführung von HelloWorld#howdy

Template

Page 62: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

25

Head Merge

Template

Page 63: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

25

Head Merge

Template

<lift:surround with="default" at="content"> <head><script type="text/javascript">...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p></lift:surround>

/index.html

Page 64: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

25

Head Merge

Template

<lift:surround with="default" at="content"> <head><script type="text/javascript">...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p></lift:surround>

/index.html

/templates-hidden/default.html

<html xmlns="..." xmlns:lift="http://liftweb.net/"> <head>...</head> <body>

...<lift:bind name="content" />

</body></html>

Page 65: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

25

Head Merge

Template

<lift:surround with="default" at="content"> <head><script type="text/javascript">...</script>...</head> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p></lift:surround>

/index.html

/templates-hidden/default.html

<html xmlns="..." xmlns:lift="http://liftweb.net/"> <head>...</head> <body>

...<lift:bind name="content" />

</body></html>

Page 66: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

ScopesSStateful SnippetRequestVarSessionVarScala Object (Singleton)

26

Page 67: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Internationalisierung / I18njava.util.Localejava.util.ResourceBundle

LiftRules.resourceNames

Ermittlung der aktuellen SpracheLiftRules.localeCalculator

Request-HeaderFallback: Locale.getDefault()

SnippetsS.?

Templates

27

<lift:loc locid="lift">Aufzug</lift:loc><lift:loc>lift</lift:loc>

Page 68: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Persistenz in LiftMapperRecordJPAJDOHibernate...

Lift selbst ist Persistenz agnostisch

28

Page 69: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

AJAX in LiftSHtml

ajaxButtonajaxTextajaxCheckbox...

29

def render(in: NodeSeq): NodeSeq =SHtml.ajaxButton("Click me ;)", () => {

println("Yes, thanks!") JsCmds.SetHtml("click-div", Text("Yes, thanks!"))

})

Page 70: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

30

in Action ;)

Page 71: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

EntwicklungsumgebungJava (>= 5)Maven (>= 2.0.9)Web-Container (Jetty, Tomcat, ...)

Optional, aber nützlichJavaRebel (JVM Plugin / Java Agent)IDE mit Scala Support / Plugin (Eclipse, IDEA, Netbeans, ...)

http://www.scala-lang.org/scala-eclipse-plugin

31

Page 72: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

32

Projekt anlegen

Page 73: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

32

Projekt anlegen

$mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=1.0 -DgroupId=de.inovex.jax2009.lift -DartifactId=lift-demo

Page 74: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

32

Projekt anlegen

$mvn archetype:generate -U -DarchetypeGroupId=net.liftweb -DarchetypeArtifactId=lift-archetype-basic -DarchetypeVersion=1.0 -DgroupId=de.inovex.jax2009.lift -DartifactId=lift-demo

$cd lift-demo && mvn eclipse:eclipse

Import in Eclipse vorbereiten

Page 75: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

33

Projektlayout

Page 76: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

33

Projektlayout

Page 77: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

33

Projektlayout

Page 78: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

34

Ausführen

Page 79: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

34

Ausführen

$mvn jetty:run

Page 80: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

34

Ausführen

$mvn jetty:run

Page 81: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

35

index.html

Page 82: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

Page 83: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 84: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 85: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 86: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 87: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 88: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 89: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 90: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

import java.util.Date

class HelloWorld { def howdy = <span>Welcome to lift-demo at {new Date}</span> }

<lift:surround with="default" at="content"> <h2>Welcome to your project!</h2> <p><lift:helloWorld.howdy /></p> </lift:surround>

35

index.html

HelloWorld.scala

Page 91: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

36

default.html

Page 92: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 93: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 94: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 95: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 96: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 97: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

<div class="container"> <div class="column span-12 last" style="text-align: right"> <h1 class="alt">lift-demo <img id="ajax-loader" style="display:none; margin-bottom: 0px; margin-left: 5px" src="/images/ajax-loader.gif"/></h1> </div> <hr/> <div class="column span-6 colborder sidebar"> <hr class="space" /> <lift:Menu.builder /> <div> <lift:snippet type="msgs"/> <hr class="space" /> </div> </div> <div class="column span-17 last"> <lift:bind name="content" /> </div> <hr /> <div class="column span-23 last" style="text-align: center"> <h4 class="alt"> <a href="http://liftweb.net"><i>Lift</i></a> is Copyright 2007-2009 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.</h4> </div> </div> 36

default.html

Page 98: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

37

Boot.scala

Page 99: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

37

Boot.scala def boot { if (!DB.jndiJdbcConnAvailable_?) DB.defineConnectionManager(DefaultConnectionIdentifier, DBVendor)

// where to search snippet LiftRules.addToPackages("de.inovex.jax2009.lift") // create or update the database schema Schemifier.schemify(true, Log.infoF _, User)

// build site map val entries = Menu(Loc("Home", List("index"), "Home")) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*))

// Show the spinny image when an Ajax call starts LiftRules.ajaxStart = Full(() => LiftRules.jsArtifacts.show("ajax-loader").cmd)

// Make the spinny image go away when it ends LiftRules.ajaxEnd = Full(() => LiftRules.jsArtifacts.hide("ajax-loader").cmd)

// force the request to be UTF-8 LiftRules.early.append(makeUtf8)

S.addAround(DB.buildLoanWrapper) }

Page 100: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

38

Rekursive Template Komposition

Page 101: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

38

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> }

Page 102: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

38

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> }

Page 103: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

38

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> }

Page 104: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

38

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> }

Page 105: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

Page 106: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

Page 107: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

Page 108: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

Page 109: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

Page 110: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

// in boot.scala: val entries = Menu(Loc("Home", List("index"), "Home")) :: Menu(Loc("form1", List("veryFirstForm"), "Example")) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*))

Page 111: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

39

Formulare <lift:surround with="default" at="content">

<h2>Very first form example:</h2> <p> <lift:FormExample form="POST"> <f:name><input type="text"/></f:name> <input type="submit" value="Post"/> </lift:FormExample> </p> </lift:surround>

class FormExample { def render(xhtml: NodeSeq) = { bind("f", xhtml, "name" -> text("", println(_))) } }

// in boot.scala: val entries = Menu(Loc("Home", List("index"), "Home")) :: Menu(Loc("form1", List("veryFirstForm"), "Example")) :: User.sitemap LiftRules.setSiteMap(SiteMap(entries:_*))

Page 112: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

40

Formulare

Page 113: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

40

Formulare

Page 114: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

40

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

Formulare

Page 115: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

40

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

Formulare

Page 116: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

41

more in Action ;)

Page 117: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Beispiel-Applikation(en)Scala Actors / CometModelle / OR-MappingSiteMapMessages...

42

Page 118: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Beispiel-Applikation(en)Scala Actors / CometModelle / OR-MappingSiteMapMessages...

42

Demo !

Page 119: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

43

Zusammenfassung

Page 120: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

44

Page 121: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

ProSehr schicke Sprachfeatures„Best of all“ PrinzipJunge und dynamische CommunitySehr gut für interaktive Webbapplikationen („Real time web“)Native, volle JVM Geschwindigkeit100% kompatibel mit JavaLäuft auf Standard Servlet-Container (Jetty, Tomcat, ...)

44

Page 122: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

ProSehr schicke Sprachfeatures„Best of all“ PrinzipJunge und dynamische CommunitySehr gut für interaktive Webbapplikationen („Real time web“)Native, volle JVM Geschwindigkeit100% kompatibel mit JavaLäuft auf Standard Servlet-Container (Jetty, Tomcat, ...)

ConsSteile LernkurveWenig 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

Page 123: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

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 "test" 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 Firefox 3.1 support) 45

Page 124: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Ressourcen im NetzScala

http://scala-lang.orgLift

http://liftweb.net/http://liftweb.net/docs/getting_started.htmlhttp://wiki.liftweb.net/http://github.com/dpp/liftweb

Lift Buch: „Exploring Lift“http://groups.google.com/group/the-lift-bookhttp://github.com/tjweir/liftbook/

46

Page 125: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Exploring Lift Mail 2009, oder LyX Version!Derek Chen-Becker, Tyler Weir, Marius Danciu

Beginning ScalaMail 2009David Pollak

Programming in ScalaMartin Odersky, Lex Spoon, and Bill Venners

...47

Page 126: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Tobias JochSystem ArchitectureProject Management

inovex GmbHKarlsruher Straße 7175179 Pforzheim

0173.3181 [email protected]

Fragen & Antworten

Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.

Page 127: GeLiftete Web-Applikation mit Scala - Tobias Joch - inovex GmbH

Tobias JochSystem ArchitectureProject Management

inovex GmbHKarlsruher Straße 7175179 Pforzheim

0173.3181 [email protected]

Vielen Dank! ;)

Wir nutzen Technologien, um unsere Kunden glücklich zu machen. Und uns selbst.


Recommended