SlideShare uma empresa Scribd logo
1 de 18
Lift 2.0

Web Framework
Powered by Scala
          (Johansson)
Hybrid programming => OOP + FP


    foldLeft, map, reduce, etc ...

         pattern matching

         class, object, trait

            concurency


   Is Scala better than Java?
Lift Architecture
Lift offers simple API to configure web
               application
                    SiteMap

                  UrlRewriting

              Database connection

           Requests specific handling

              Localization changing

        Customizing 404 - Page Not Found

                    web.xml
                      ...
SiteMap


val entries =
    Menu(Loc("404", List("404"), "404")) ::
    Menu(Loc("search", List("search"), "search")) ::
    Nil

LiftRules.setSiteMap(SiteMap(entries: _*))
UrlRewriting

LiftRules.statelessRewrite.append {
     case RewriteRequest(
           ParsePath(
              "home" :: articleId :: Nil, _, _, _), _, _) =>
       RewriteResponse(
           List("products"),
           Map("articleId" -> articleId))
   }
Localization

LiftRules.localeCalculator =
        (req: Box[HTTPRequest]) => {
          Localization.is openOr
                req match {
            case Full(e: HTTPRequest) =>
             (e.locale) openOr Locale.getDefault
            case _ => Locale.getDefault
          }
        }
Variables - Session scope

    object Localization extends
  SessionVar[Box[Locale]](Empty)


          Localization.is


         Localization.set
Variables - request scope

      The magic with S object

             S.param

               S.attr

               S.set


 S object request/response settings
MVC
 Model

Template

Snippet

 View
Model

Mapper - ORM Mapping

class NewsletterReceiver extends
    LongKeyedMapper[NewsletterReceiver] with IdPK {
   ...
}

Boot class:
  DB.defineConnectionManager(...)

object DBVendor extends ConnectionManager {
  ...
}
Template
                          default.html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>...</head>
<body>
  <lift:bind name="content">
  </lift:bind>
  ...
</body>

                           index.html:

<lift:surround with="default" at="content">
   <lift:Hello.world />
</lift:surround>
Template - continued...
                       default.html:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>...</head>
<body>
  <lift:embed what="welcome" />
  ...
</body>

                      welcome.html:

<div id="WelcomeDiv">
  <p>Herzlich Wilkommen!!!</p>
</div>
Snippet
Somewhere in template:

                         <lift:Articles>
                             <s:table/>
                         </lift:Articles>

What's behind the scene?

  class Articles extends StatefulSnippet {
     def render(in : NodeSeq) : NodeSeq = {
       val table = ...
       bind("s", in, "table" -> table)
     }
  }
View
class ExpenseView extends LiftView {
   var expenseItems = ...

    override def dispatch = {
      case "enumerate" => doEnumerate _
    }

    def doEnumerate () : NodeSeq = {
      ...
      <lift:surround with="default" at="content">
      { expenseItems.toTable }
      </lift:surround>
    }
}
Forms
<lift:Search.generateForm form="POST">
   <f:search/>
   <f:submit/>
</lift:Search.generateForm>


class Search extends StatefulSnippet {
   var searchText

    def generateForm(in : NodeSeq) : NodeSeq =
      bind("f", in,
        "search" -> SHtml.text(searchText, searchText = _)
        "submit" -> SHtml.submit("Search", processSearch))
}
JavaScript + jQuery and the band

                  JsExp

                 JsCmd

                JsCmds._

                 JsRaw


         artifact defining in Boot
Comet applications

                                    Comet - according to wiki:
Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data
                                  to a browser, without the browser explicitly requesting it.



                                                 Scala Actors

                                                   Ajax in Lift

                                       SHtml.ajaxCall
                                      SHtml.ajaxForm
                          ajaxText, ajaxSubmit and many more...

Mais conteúdo relacionado

Mais procurados

Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryWilliam Candillon
 
20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-finalDavid Lapsley
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling WebStackAcademy
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Andy Bunce
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSphilogb
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?Tomasz Bak
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative versionWO Community
 
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSencha
 
Intro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneIntro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneMarius Soutier
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js FundamentalsMark
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sRoel Hartman
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web AppsMark
 
Summer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scalarostislav
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Jan Helke
 

Mais procurados (20)

Cutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQueryCutting Edge Data Processing with PHP & XQuery
Cutting Edge Data Processing with PHP & XQuery
 
20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final20141001 delapsley-oc-openstack-final
20141001 delapsley-oc-openstack-final
 
jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling jQuery - Chapter 4 - DOM Handling
jQuery - Chapter 4 - DOM Handling
 
Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application Benchx: An XQuery benchmarking web application
Benchx: An XQuery benchmarking web application
 
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJSJavaScript para Graficos y Visualizacion de Datos - BogotaJS
JavaScript para Graficos y Visualizacion de Datos - BogotaJS
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?How to replace rails asset pipeline with webpack?
How to replace rails asset pipeline with webpack?
 
wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?wtf is in Java/JDK/wtf7?
wtf is in Java/JDK/wtf7?
 
iOS for ERREST - alternative version
iOS for ERREST - alternative versioniOS for ERREST - alternative version
iOS for ERREST - alternative version
 
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
 
Backbone
BackboneBackbone
Backbone
 
Intro to sbt-web
Intro to sbt-webIntro to sbt-web
Intro to sbt-web
 
Intro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG CologneIntro to Scala.js - Scala UG Cologne
Intro to Scala.js - Scala UG Cologne
 
Angular.js Fundamentals
Angular.js FundamentalsAngular.js Fundamentals
Angular.js Fundamentals
 
My Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API'sMy Top 5 APEX JavaScript API's
My Top 5 APEX JavaScript API's
 
Building Go Web Apps
Building Go Web AppsBuilding Go Web Apps
Building Go Web Apps
 
Summer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and ScalaSummer - The HTML5 Library for Java and Scala
Summer - The HTML5 Library for Java and Scala
 
Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']Bye bye $GLOBALS['TYPO3_DB']
Bye bye $GLOBALS['TYPO3_DB']
 
Oak Lucene Indexes
Oak Lucene IndexesOak Lucene Indexes
Oak Lucene Indexes
 
Pyramid REST
Pyramid RESTPyramid REST
Pyramid REST
 

Semelhante a Lift 2.0 Web Framework Powered by Scala (Johansson

Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkIndicThreads
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Frameworkvhazrati
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAERon Reiter
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)Beau Lebens
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascriptDsixE Inc
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIRob Windsor
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)Jo Cranford
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorialKat Roque
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Yuriy Shapovalov
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajaxs_pradeep
 
Kubernetes Operators With Scala
Kubernetes Operators With ScalaKubernetes Operators With Scala
Kubernetes Operators With ScalaPeter Barron
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortalJennifer Bourey
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworksEric Guo
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsSoós Gábor
 

Semelhante a Lift 2.0 Web Framework Powered by Scala (Johansson (20)

Overview Of Lift Framework
Overview Of Lift FrameworkOverview Of Lift Framework
Overview Of Lift Framework
 
Overview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web FrameworkOverview of The Scala Based Lift Web Framework
Overview of The Scala Based Lift Web Framework
 
Scala based Lift Framework
Scala based Lift FrameworkScala based Lift Framework
Scala based Lift Framework
 
Writing HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAEWriting HTML5 Web Apps using Backbone.js and GAE
Writing HTML5 Web Apps using Backbone.js and GAE
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Soa development using javascript
Soa development using javascriptSoa development using javascript
Soa development using javascript
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Introduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST APIIntroduction to the SharePoint Client Object Model and REST API
Introduction to the SharePoint Client Object Model and REST API
 
React on Rails - RailsConf 2017 (Phoenix)
 React on Rails - RailsConf 2017 (Phoenix) React on Rails - RailsConf 2017 (Phoenix)
React on Rails - RailsConf 2017 (Phoenix)
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Html5 For Jjugccc2009fall
Html5 For Jjugccc2009fallHtml5 For Jjugccc2009fall
Html5 For Jjugccc2009fall
 
Ajax tutorial
Ajax tutorialAjax tutorial
Ajax tutorial
 
Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4Single Page Applications on JavaScript and ASP.NET MVC4
Single Page Applications on JavaScript and ASP.NET MVC4
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Building Applications Using Ajax
Building Applications Using AjaxBuilding Applications Using Ajax
Building Applications Using Ajax
 
Kubernetes Operators With Scala
Kubernetes Operators With ScalaKubernetes Operators With Scala
Kubernetes Operators With Scala
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Rails 6 frontend frameworks
Rails 6 frontend frameworksRails 6 frontend frameworks
Rails 6 frontend frameworks
 
Javascript frameworks: Backbone.js
Javascript frameworks: Backbone.jsJavascript frameworks: Backbone.js
Javascript frameworks: Backbone.js
 

Lift 2.0 Web Framework Powered by Scala (Johansson

  • 2. Powered by Scala (Johansson) Hybrid programming => OOP + FP foldLeft, map, reduce, etc ... pattern matching class, object, trait concurency Is Scala better than Java?
  • 4. Lift offers simple API to configure web application SiteMap UrlRewriting Database connection Requests specific handling Localization changing Customizing 404 - Page Not Found web.xml ...
  • 5. SiteMap val entries = Menu(Loc("404", List("404"), "404")) :: Menu(Loc("search", List("search"), "search")) :: Nil LiftRules.setSiteMap(SiteMap(entries: _*))
  • 6. UrlRewriting LiftRules.statelessRewrite.append { case RewriteRequest( ParsePath( "home" :: articleId :: Nil, _, _, _), _, _) => RewriteResponse( List("products"), Map("articleId" -> articleId)) }
  • 7. Localization LiftRules.localeCalculator = (req: Box[HTTPRequest]) => { Localization.is openOr req match { case Full(e: HTTPRequest) => (e.locale) openOr Locale.getDefault case _ => Locale.getDefault } }
  • 8. Variables - Session scope object Localization extends SessionVar[Box[Locale]](Empty) Localization.is Localization.set
  • 9. Variables - request scope The magic with S object S.param S.attr S.set S object request/response settings
  • 11. Model Mapper - ORM Mapping class NewsletterReceiver extends LongKeyedMapper[NewsletterReceiver] with IdPK { ... } Boot class: DB.defineConnectionManager(...) object DBVendor extends ConnectionManager { ... }
  • 12. Template default.html: <html xmlns="http://www.w3.org/1999/xhtml"> <head>...</head> <body> <lift:bind name="content"> </lift:bind> ... </body> index.html: <lift:surround with="default" at="content"> <lift:Hello.world /> </lift:surround>
  • 13. Template - continued... default.html: <html xmlns="http://www.w3.org/1999/xhtml"> <head>...</head> <body> <lift:embed what="welcome" /> ... </body> welcome.html: <div id="WelcomeDiv"> <p>Herzlich Wilkommen!!!</p> </div>
  • 14. Snippet Somewhere in template: <lift:Articles> <s:table/> </lift:Articles> What's behind the scene? class Articles extends StatefulSnippet { def render(in : NodeSeq) : NodeSeq = { val table = ... bind("s", in, "table" -> table) } }
  • 15. View class ExpenseView extends LiftView { var expenseItems = ... override def dispatch = { case "enumerate" => doEnumerate _ } def doEnumerate () : NodeSeq = { ... <lift:surround with="default" at="content"> { expenseItems.toTable } </lift:surround> } }
  • 16. Forms <lift:Search.generateForm form="POST"> <f:search/> <f:submit/> </lift:Search.generateForm> class Search extends StatefulSnippet { var searchText def generateForm(in : NodeSeq) : NodeSeq = bind("f", in, "search" -> SHtml.text(searchText, searchText = _) "submit" -> SHtml.submit("Search", processSearch)) }
  • 17. JavaScript + jQuery and the band JsExp JsCmd JsCmds._ JsRaw artifact defining in Boot
  • 18. Comet applications Comet - according to wiki: Comet is a neologism to describe a web application model in which a long-held HTTP request allows a web server to push data to a browser, without the browser explicitly requesting it. Scala Actors Ajax in Lift SHtml.ajaxCall SHtml.ajaxForm ajaxText, ajaxSubmit and many more...