SlideShare ist ein Scribd-Unternehmen logo
1 von 40
Downloaden Sie, um offline zu lesen
Lift Framework!


     Winston!
Topics!

•    Coding	
  Monk/Winston	
  
•    View	
  First	
  v.s.	
  MVC	
  
•    Version	
  Assump9ons	
  &	
  Configura9ons	
  
•    Template	
  –	
  snippet	
  &	
  value	
  binding	
  
•    Javascript	
  from	
  LiE	
  
•    Ajax	
  &	
  Coment	
  
•    Fast	
  &	
  Easy	
  API	
  
•    My	
  Love	
  &	
  Pain	
  with	
  LiE	
  

                                                             2!
Slide and Sample Project!

•  hMp://engineering.fliptop.com/2012/08/25/	
  




                                                  3!
Coding Monk/Winston!

•  Love	
  wine/Learning	
  Whiskey	
  
•  Love	
  scala/java,	
  python,	
  liE,	
  django	
  
•  Struts	
  -­‐>	
  Struts	
  2	
  -­‐>	
  Spring	
  -­‐>	
  django	
  -­‐>	
  rails	
  -­‐>	
  
   liE	
  
•  Wish	
  List:	
  big	
  data/data	
  mining/machine	
  
   learning,	
  the	
  architecture	
  and	
  algorithm	
  
•  Having	
  a	
  lot	
  of	
  fun	
  at	
  fliptop	
  



                                                                                                    4!
The problem with MVC!

•  MVC	
  Architecture	
  Graph	
  
•  Because	
  complex	
  HTML	
  pages	
  rarely	
  contain	
  a	
  
   dominant	
  piece	
  of	
  logic...	
  a	
  single	
  controller...	
  
   but	
  contain	
  many	
  different	
  components.	
  	
  
•  We	
  end	
  up	
  pu]ng	
  a	
  lot	
  of	
  logic	
  into	
  a	
  single	
  
   controller	
  and	
  view.	
  	
  




                                                                                    5!
The problem with MVC!




                        6!
A Giant Controller!




                      7!
Lift!

•  you	
  define	
  the	
  collec9on	
  of	
  components	
  to	
  be	
  
   rendered	
  in	
  the	
  resul9ng	
  HTML	
  page	
  in	
  the	
  
   view.	
  
•  Simple	
  and	
  Clear	
  




                                                                          8!
Lift!




        9!
Lift!




        10!
Assumptions!

•  Use	
  maven	
  to	
  set	
  up	
  LiE	
  
•  Use	
  XHTML	
  liE,	
  not	
  HTML5	
  liE	
  
•  HTML5	
  StyleSnippet:	
  



•  XHTML	
  Style	
  Snippet:	
  




                                                     11!
Start Up a lift project!

mvn	
  archetype:generate	
  	
  
	
  -­‐DarchetypeGroupId=net.liEweb	
  	
  
	
  -­‐DarchetypeAr9factId=liE-­‐archetype-­‐basic_2.8.1	
  	
  
	
  -­‐DarchetypeVersion=2.3	
  	
  
	
  -­‐DarchetypeRepository=hMp://scala-­‐tools.org/repo-­‐
        releases	
  	
  
	
  -­‐DremoteRepositories=hMp://scala-­‐tools.org/repo-­‐
        releases	
  	
  
	
  -­‐DgroupId=com.fliptop.liE	
  	
  
	
  -­‐Dar9factId=fliptop_rocks	
  	
  
	
  -­‐Dversion=1.0	
  
                                                                    12!
Project Structure!




                     13!
Run it!!

•  mvn	
  jeMy:run	
  
•  hMp://localhost:8080	
  

•  You	
  now	
  got	
  ProtoUser	
  Module	
  (we	
  won’t	
  
   cover	
  today)	
  with	
  AddUserMenusAEer	
  set	
  up	
  
   for	
  you.	
  
   (More	
  on	
  ProtoUser:	
  	
  
   hMp://blog.thegodcode.net/post/141132296/
   super-­‐quick-­‐start-­‐with-­‐liEs-­‐protouser)	
  

                                                                  14!
Boot.scala!

•  No	
  xml	
  configura9on!	
  Pure	
  code!!	
  

•  LiERules	
  
•  DB,	
  Proper9es	
  and	
  Run	
  modes	
  
•  SiteMap:	
  
   –  Menu	
  
   –  Access	
  Control	
  



                                                     15!
Create a page!

•  Set	
  up	
  a	
  path	
  in	
  Boot.scala	
  
•  Create	
  an	
  HTML	
  page	
  in	
  webapp	
  or	
  a	
  view	
  
   class	
  in	
  class	
  folder.	
  
•  Fill	
  in	
  the	
  snippets	
  if	
  using	
  HTML	
  pages.	
  

•  Request	
  Rou9ng:	
  
    –  Template	
  -­‐>	
  View	
  
    –  We	
  are	
  using	
  Template,	
  not	
  view	
  


                                                                         16!
Snippet 101!

•  snippet101.html	
  
   <liE:surround	
  with="default"	
  at="content”>	
  
   	
   	
  <liE:SnippetExp.snipprt101/>	
  
   </liE:surround>	
  
•  SnippetExp.scala	
  
   class	
  SnippetExp	
  {	
  
   	
   	
  def	
  snipprt101:NodeSeq	
  =	
  	
  
   	
   	
   	
  <div>This	
  is	
  a	
  very	
  bad	
  prac9ce!!</div>	
  
   }	
  

                                                                              17!
Bad Practice!

•  A	
  lot	
  of	
  HTML	
  in	
  a	
  snippet	
  code	
  
   class	
  SnippetExp	
  {	
  
    	
   	
  def	
  thisIsBad:NodeSeq	
  =	
  {	
  
    	
   	
   	
  val	
  goodCode	
  =	
  false	
  
    	
   	
   	
  val	
  badCode	
  =	
  if(goodCode)	
  “not	
  at	
  all”	
  
   	
   	
   	
  else	
  “bad	
  prac9ce,	
  HTML	
  in	
  snippet!!”	
  
    	
   	
   	
  <div>{badCode}</div>	
  
    	
   	
  }	
  
   }	
  

                                                                                  18!
Complex Snippet: data binding!

•  simple_form.html	
  
   <liE:surround	
  with="default"	
  at="content”>	
  
   	
  <liE:SnippetExp.bindingExample	
  
   form="POST”>	
  
   	
   	
  <p>Do	
  Something	
  with	
  your	
  email:</p>	
  
   	
   	
  <p><entry:email/></p>	
  
   	
   	
  <p><entry:submit/></p>	
  
   	
  </liE:SnippetExp.bindingExample>	
  
   </liE:surround>	
  

                                                                   19!
A Simple Form Snippet!

def	
  bindingExample(xhtml:NodeSeq):NodeSeq	
  =	
  {	
  
      	
  var	
  email	
  =	
  ""	
  
      	
  def	
  process	
  (){	
  
      	
   	
  print("The	
  email	
  is:	
  "	
  +	
  email)	
  
      	
  }	
  
      	
  bind("entry",	
  xhtml,	
  
      	
  	
  “email”	
  -­‐>	
  SHtml.text(email,	
  email	
  =	
  _,	
  
           	
  "id”>"email"),	
  
      	
  	
  	
  "submit"	
  -­‐>	
  SHtml.submit("search",	
  process))	
  
}	
  
                                                                                20!
Recursive Binding!

•  Rendering	
  a	
  list	
  or	
  a	
  table	
  
•  recursive_binding.html	
  
<liE:SnippetExp.recursiveBinding>	
  
   	
  <table>	
  
   	
  	
  	
   	
  <entry:lis9tem>	
  
   	
  	
  	
  	
  	
  <tr>	
  
   	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  <td><item:name/></td><td><item:email/></td>	
  
   	
  	
  	
  	
  	
  </tr>	
  
   	
   	
  </entry:lis9tem>	
  
   	
  </table>	
  
</liE:SnippetExp.recursiveBinding>	
  
                                                                                             21!
Recursive Binding!

def	
  recursiveBinding(xhtml:NodeSeq):NodeSeq	
  =	
  {	
  
              	
  val	
  theList	
  =	
  new	
  ListBuffer[(String,	
  String)]	
  
              	
  theList	
  +=	
  new	
  Tuple2("robbie@fliptop.com",	
  "Robbie	
  Cheng")	
  
              	
  theList	
  +=	
  new	
  Tuple2("winston@fliptop.com",	
  "Winston	
  Chen")	
  
              	
  bind("entry",	
  xhtml,	
  "lis9tem"	
  -­‐>	
  theList.toList.flatMap(	
  
              	
   	
   	
  item	
  =>	
  {	
  
              	
   	
   	
        	
  bind("item",	
  chooseTemplate("entry","lis9tem",	
  xhtml),	
  	
  
              	
   	
   	
        	
        	
  "email"	
  -­‐>	
  item._1,	
  
              	
   	
   	
        	
        	
  "name"	
  -­‐>	
  item._2	
  
              	
   	
   	
        	
  )	
  
              	
   	
   	
  }	
  
              	
   	
  )	
  
              	
  )	
  
	
  	
  }	
  
                                                                                                             22!
Javascript Integration!

•    Javascript	
  expressions	
  and	
  statements	
  
•    Javascript	
  forms	
  
•    Ajax	
  
•    Comet	
  (Long	
  pulling)	
  




                                                          23!
Javascript Expressions/Statements!

•  The	
  magic	
  Call	
  func9on	
  
<script>	
  
func9on	
  this_is_an_alert_triggered_by_liE_call(){	
  
      	
  alert("This	
  is	
  an	
  alert	
  triggered	
  by	
  liE	
  call()!!")	
  
}	
  
</script>	
  
<liE:JsSnippetExp.call>	
  
<input	
  id="buMon"	
  type="buMon"	
  value="Click	
  me"	
  />	
  
</liE:JsSnippetExp.call>	
  
Snippet:	
  
def	
  call	
  =	
  	
  
      	
  	
  	
  "#buMon	
  [onclick]"	
  #>	
  JE.Call
          ("this_is_an_alert_triggered_by_liE_call",	
  "").toJsCmd	
  
                                                                                         24!
Json Forms!

•  Let’s	
  look	
  at	
  the	
  code	
  directly:	
  JsSnippetExp	
  




                                                                         25!
Ajax!

•  Template:	
  
<liE:JsSnippetExp.ajaxBuMon>	
  
   	
  <item:buMon/>	
  
</liE:JsSnippetExp.ajaxBuMon>	
  
<div	
  id="ajaxb"></div>	
  
•  Snippet:	
  
def	
  updateText	
  =	
  SetHtml("ajaxb",	
  Text("Fliptop	
  is	
  a	
  great	
  
       company!!"))	
  
def	
  ajaxBuMon(xhtml:NodeSeq):NodeSeq	
  =	
  bind("item",	
  
       xhtml,	
  "buMon"	
  -­‐>	
  SHtml.ajaxBuMon(Text("Press	
  me"),	
  
       ()=>updateText))	
  
                                                                                      26!
Comet!


Ajax!
Comet!


Comet!
Comet!

•    Lift: Long Pulling!
•    Must put comets in comet folder.!
•    Extend CometActor!
•    Use tag: <lift:comet>  !

•  Letʼs look at the code: CometExp.scala!
•  Reference:

   exploring.liftweb.net/master/index-11.html!

                                                 29!
REST API So Easy!

•  Use	
  RestHelper	
  to	
  write	
  up	
  the	
  code.	
  
•  Configure	
  it	
  on	
  Boot.scala	
  

•  Let’s	
  look	
  at	
  Rest.scala	
  
•  Here	
  you	
  go!!	
  It’s	
  that	
  easy.	
  
•  Reference:	
  simply.liEweb.net/index-­‐
   Chapter-­‐11.html	
  


                                                                30!
Conclusions!

•  LiE	
  tackles	
  Web	
  from	
  a	
  view-­‐first	
  perspec9ve.	
  
•  LiE	
  gives	
  you	
  js/ajax/comet	
  for	
  free.	
  
•  LiE	
  also	
  gives	
  you	
  rest	
  API	
  for	
  free.	
  



•  All	
  feature	
  goes	
  to	
  backend,	
  designs	
  frontend.	
  
•  No	
  more	
  plumbing	
  yourself.	
  


                                                                          31!
Why I love Lift!

•  Get	
  all	
  the	
  feature	
  done	
  at	
  backend	
  
•  The	
  Snippet	
  logic	
  makes	
  much	
  more	
  sense	
  
   than	
  MVC	
  for	
  me.	
  (although	
  I	
  love	
  django	
  too)	
  
•  API	
  so	
  easy,	
  no	
  much	
  code	
  needed	
  




                                                                               32!
Why I hate Lift!

•  It’s	
  really	
  hard	
  to	
  get	
  HTML/XML	
  out	
  of	
  snippet	
  
   code.	
  
•  Learning	
  curve	
  is	
  s9ff	
  if	
  you	
  are	
  not	
  used	
  to	
  its	
  
   logic.	
  
•  Try	
  s9ck	
  to	
  the	
  latest	
  version.	
  
•  Too	
  many	
  ways	
  to	
  write	
  it.	
  




                                                                                        33!
Free Books!

•  Exploring	
  LiE:	
  exploring.liEweb.net	
  
•  Simply	
  LiE:	
  simply.liEweb.net	
  
•  LiE	
  Cookbook:	
  cookbook.liEweb.net	
  




                                                   34!
References!

•  David	
  Pollak	
  On	
  LiE	
  Framework	
  and	
  Scala	
  
   www.infoq.com/interviews/LiE-­‐Scala-­‐David-­‐
   Pollak	
  
•  Example	
  &	
  Demo	
  Site:	
  demo.liEweb.net	
  
•  Start	
  Up	
  Project	
  with	
  Maven:	
  
   www.assembla.com/wiki/show/liEweb/
   Using_Maven	
  



                                                                   35!
Get to me!

•  Email:	
  wisnton@fliptop.com	
  
•  URLs:	
  
   –  hMp://www.repfans.com/profile/33335/Winston
      %20Chen	
  
   –  hMp://careers.stackoverflow.com/wingchen	
  




                                                    36!
The last Q&A!


    Winston!
Model!

•  Mapper	
  or	
  Record	
  

•  Take	
  a	
  look	
  at	
  here:	
  
   stackoverflow.com/ques9ons/6564332/when-­‐
   to-­‐use-­‐mapper-­‐or-­‐record-­‐in-­‐liE	
  




                                                    38!
Menu Configurations!

•  stackoverflow.com/ques9ons/2175246/
   liEweb-­‐menu-­‐customiza9on	
  




                                        39!
Thank you.!

Weitere ähnliche Inhalte

Was ist angesagt?

Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Patrick Lauke
 
HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs Silverlight
Matt Casto
 

Was ist angesagt? (20)

Rails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on RailsRails Girls: Programming, Web Applications and Ruby on Rails
Rails Girls: Programming, Web Applications and Ruby on Rails
 
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
Brave new world of HTML5 - Interlink Conference Vancouver 04.06.2011
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs Silverlight
 
Ruby MVC from scratch with Rack
Ruby MVC from scratch with RackRuby MVC from scratch with Rack
Ruby MVC from scratch with Rack
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
Finally, Professional Frontend Dev with ReactJS, WebPack & Symfony (Symfony C...
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
Front End Performance
Front End PerformanceFront End Performance
Front End Performance
 
Front end performance tip
Front end performance tipFront end performance tip
Front end performance tip
 
Ajax Security
Ajax SecurityAjax Security
Ajax Security
 
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJRealize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
Realize mais com HTML 5 e CSS 3 - 16 EDTED - RJ
 
Grok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb updateGrok Drupal (7) Theming - 2011 Feb update
Grok Drupal (7) Theming - 2011 Feb update
 
Introducing RaveJS: Spring Boot concepts for JavaScript applications
Introducing RaveJS: Spring Boot concepts for JavaScript applicationsIntroducing RaveJS: Spring Boot concepts for JavaScript applications
Introducing RaveJS: Spring Boot concepts for JavaScript applications
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimization
 
Celix universal OSGi
Celix universal OSGiCelix universal OSGi
Celix universal OSGi
 
Everything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the WebEverything is Awesome - Cutting the Corners off the Web
Everything is Awesome - Cutting the Corners off the Web
 

Andere mochten auch

3グーグルドキュメントの使い方2
3グーグルドキュメントの使い方23グーグルドキュメントの使い方2
3グーグルドキュメントの使い方2
Hati Miura
 
Dallas GUG Lift Presentation
Dallas GUG Lift PresentationDallas GUG Lift Presentation
Dallas GUG Lift Presentation
Brent Lemons
 

Andere mochten auch (8)

293% Lift in Web Traffic by Leveraging Content Marketing & LinkedIn
293% Lift in Web Traffic by Leveraging Content Marketing & LinkedIn293% Lift in Web Traffic by Leveraging Content Marketing & LinkedIn
293% Lift in Web Traffic by Leveraging Content Marketing & LinkedIn
 
Lift web framework
Lift web frameworkLift web framework
Lift web framework
 
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT frameworkCodeweek 2015 - Reactive Web Applications with Scala and LIFT framework
Codeweek 2015 - Reactive Web Applications with Scala and LIFT framework
 
***************
******************************
***************
 
3グーグルドキュメントの使い方2
3グーグルドキュメントの使い方23グーグルドキュメントの使い方2
3グーグルドキュメントの使い方2
 
Dallas GUG Lift Presentation
Dallas GUG Lift PresentationDallas GUG Lift Presentation
Dallas GUG Lift Presentation
 
Lift web framework and Scala programming language talk
Lift web framework and Scala programming language talkLift web framework and Scala programming language talk
Lift web framework and Scala programming language talk
 
Intro lift
Intro liftIntro lift
Intro lift
 

Ähnlich wie Lift talk

Ähnlich wie Lift talk (20)

JavaScripts & jQuery
JavaScripts & jQueryJavaScripts & jQuery
JavaScripts & jQuery
 
JS Essence
JS EssenceJS Essence
JS Essence
 
TYPO3 Transition Tool
TYPO3 Transition ToolTYPO3 Transition Tool
TYPO3 Transition Tool
 
Killing the Angle Bracket
Killing the Angle BracketKilling the Angle Bracket
Killing the Angle Bracket
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
JavaScript Performance Patterns
JavaScript Performance PatternsJavaScript Performance Patterns
JavaScript Performance Patterns
 
CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!CBDW2014 - MockBox, get ready to mock your socks off!
CBDW2014 - MockBox, get ready to mock your socks off!
 
Titanium Alloy Tutorial
Titanium Alloy TutorialTitanium Alloy Tutorial
Titanium Alloy Tutorial
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
2011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 52011 NetUG HH: ASP.NET MVC & HTML 5
2011 NetUG HH: ASP.NET MVC & HTML 5
 
Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)Advancing JavaScript with Libraries (Yahoo Tech Talk)
Advancing JavaScript with Libraries (Yahoo Tech Talk)
 
JavaScript performance patterns
JavaScript performance patternsJavaScript performance patterns
JavaScript performance patterns
 
Play Framework and Activator
Play Framework and ActivatorPlay Framework and Activator
Play Framework and Activator
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
The JavaFX Ecosystem
The JavaFX EcosystemThe JavaFX Ecosystem
The JavaFX Ecosystem
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
 
Java script
Java scriptJava script
Java script
 

Kürzlich hochgeladen

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 

Lift talk

  • 1. Lift Framework! Winston!
  • 2. Topics! •  Coding  Monk/Winston   •  View  First  v.s.  MVC   •  Version  Assump9ons  &  Configura9ons   •  Template  –  snippet  &  value  binding   •  Javascript  from  LiE   •  Ajax  &  Coment   •  Fast  &  Easy  API   •  My  Love  &  Pain  with  LiE   2!
  • 3. Slide and Sample Project! •  hMp://engineering.fliptop.com/2012/08/25/   3!
  • 4. Coding Monk/Winston! •  Love  wine/Learning  Whiskey   •  Love  scala/java,  python,  liE,  django   •  Struts  -­‐>  Struts  2  -­‐>  Spring  -­‐>  django  -­‐>  rails  -­‐>   liE   •  Wish  List:  big  data/data  mining/machine   learning,  the  architecture  and  algorithm   •  Having  a  lot  of  fun  at  fliptop   4!
  • 5. The problem with MVC! •  MVC  Architecture  Graph   •  Because  complex  HTML  pages  rarely  contain  a   dominant  piece  of  logic...  a  single  controller...   but  contain  many  different  components.     •  We  end  up  pu]ng  a  lot  of  logic  into  a  single   controller  and  view.     5!
  • 8. Lift! •  you  define  the  collec9on  of  components  to  be   rendered  in  the  resul9ng  HTML  page  in  the   view.   •  Simple  and  Clear   8!
  • 9. Lift! 9!
  • 10. Lift! 10!
  • 11. Assumptions! •  Use  maven  to  set  up  LiE   •  Use  XHTML  liE,  not  HTML5  liE   •  HTML5  StyleSnippet:   •  XHTML  Style  Snippet:   11!
  • 12. Start Up a lift project! mvn  archetype:generate      -­‐DarchetypeGroupId=net.liEweb      -­‐DarchetypeAr9factId=liE-­‐archetype-­‐basic_2.8.1      -­‐DarchetypeVersion=2.3      -­‐DarchetypeRepository=hMp://scala-­‐tools.org/repo-­‐ releases      -­‐DremoteRepositories=hMp://scala-­‐tools.org/repo-­‐ releases      -­‐DgroupId=com.fliptop.liE      -­‐Dar9factId=fliptop_rocks      -­‐Dversion=1.0   12!
  • 14. Run it!! •  mvn  jeMy:run   •  hMp://localhost:8080   •  You  now  got  ProtoUser  Module  (we  won’t   cover  today)  with  AddUserMenusAEer  set  up   for  you.   (More  on  ProtoUser:     hMp://blog.thegodcode.net/post/141132296/ super-­‐quick-­‐start-­‐with-­‐liEs-­‐protouser)   14!
  • 15. Boot.scala! •  No  xml  configura9on!  Pure  code!!   •  LiERules   •  DB,  Proper9es  and  Run  modes   •  SiteMap:   –  Menu   –  Access  Control   15!
  • 16. Create a page! •  Set  up  a  path  in  Boot.scala   •  Create  an  HTML  page  in  webapp  or  a  view   class  in  class  folder.   •  Fill  in  the  snippets  if  using  HTML  pages.   •  Request  Rou9ng:   –  Template  -­‐>  View   –  We  are  using  Template,  not  view   16!
  • 17. Snippet 101! •  snippet101.html   <liE:surround  with="default"  at="content”>      <liE:SnippetExp.snipprt101/>   </liE:surround>   •  SnippetExp.scala   class  SnippetExp  {      def  snipprt101:NodeSeq  =          <div>This  is  a  very  bad  prac9ce!!</div>   }   17!
  • 18. Bad Practice! •  A  lot  of  HTML  in  a  snippet  code   class  SnippetExp  {      def  thisIsBad:NodeSeq  =  {        val  goodCode  =  false        val  badCode  =  if(goodCode)  “not  at  all”        else  “bad  prac9ce,  HTML  in  snippet!!”        <div>{badCode}</div>      }   }   18!
  • 19. Complex Snippet: data binding! •  simple_form.html   <liE:surround  with="default"  at="content”>    <liE:SnippetExp.bindingExample   form="POST”>      <p>Do  Something  with  your  email:</p>      <p><entry:email/></p>      <p><entry:submit/></p>    </liE:SnippetExp.bindingExample>   </liE:surround>   19!
  • 20. A Simple Form Snippet! def  bindingExample(xhtml:NodeSeq):NodeSeq  =  {    var  email  =  ""    def  process  (){      print("The  email  is:  "  +  email)    }    bind("entry",  xhtml,      “email”  -­‐>  SHtml.text(email,  email  =  _,    "id”>"email"),        "submit"  -­‐>  SHtml.submit("search",  process))   }   20!
  • 21. Recursive Binding! •  Rendering  a  list  or  a  table   •  recursive_binding.html   <liE:SnippetExp.recursiveBinding>    <table>          <entry:lis9tem>            <tr>                      <td><item:name/></td><td><item:email/></td>            </tr>      </entry:lis9tem>    </table>   </liE:SnippetExp.recursiveBinding>   21!
  • 22. Recursive Binding! def  recursiveBinding(xhtml:NodeSeq):NodeSeq  =  {    val  theList  =  new  ListBuffer[(String,  String)]    theList  +=  new  Tuple2("robbie@fliptop.com",  "Robbie  Cheng")    theList  +=  new  Tuple2("winston@fliptop.com",  "Winston  Chen")    bind("entry",  xhtml,  "lis9tem"  -­‐>  theList.toList.flatMap(        item  =>  {          bind("item",  chooseTemplate("entry","lis9tem",  xhtml),              "email"  -­‐>  item._1,            "name"  -­‐>  item._2          )        }      )    )      }   22!
  • 23. Javascript Integration! •  Javascript  expressions  and  statements   •  Javascript  forms   •  Ajax   •  Comet  (Long  pulling)   23!
  • 24. Javascript Expressions/Statements! •  The  magic  Call  func9on   <script>   func9on  this_is_an_alert_triggered_by_liE_call(){    alert("This  is  an  alert  triggered  by  liE  call()!!")   }   </script>   <liE:JsSnippetExp.call>   <input  id="buMon"  type="buMon"  value="Click  me"  />   </liE:JsSnippetExp.call>   Snippet:   def  call  =          "#buMon  [onclick]"  #>  JE.Call ("this_is_an_alert_triggered_by_liE_call",  "").toJsCmd   24!
  • 25. Json Forms! •  Let’s  look  at  the  code  directly:  JsSnippetExp   25!
  • 26. Ajax! •  Template:   <liE:JsSnippetExp.ajaxBuMon>    <item:buMon/>   </liE:JsSnippetExp.ajaxBuMon>   <div  id="ajaxb"></div>   •  Snippet:   def  updateText  =  SetHtml("ajaxb",  Text("Fliptop  is  a  great   company!!"))   def  ajaxBuMon(xhtml:NodeSeq):NodeSeq  =  bind("item",   xhtml,  "buMon"  -­‐>  SHtml.ajaxBuMon(Text("Press  me"),   ()=>updateText))   26!
  • 29. Comet! •  Lift: Long Pulling! •  Must put comets in comet folder.! •  Extend CometActor! •  Use tag: <lift:comet>  ! •  Letʼs look at the code: CometExp.scala! •  Reference:
 exploring.liftweb.net/master/index-11.html! 29!
  • 30. REST API So Easy! •  Use  RestHelper  to  write  up  the  code.   •  Configure  it  on  Boot.scala   •  Let’s  look  at  Rest.scala   •  Here  you  go!!  It’s  that  easy.   •  Reference:  simply.liEweb.net/index-­‐ Chapter-­‐11.html   30!
  • 31. Conclusions! •  LiE  tackles  Web  from  a  view-­‐first  perspec9ve.   •  LiE  gives  you  js/ajax/comet  for  free.   •  LiE  also  gives  you  rest  API  for  free.   •  All  feature  goes  to  backend,  designs  frontend.   •  No  more  plumbing  yourself.   31!
  • 32. Why I love Lift! •  Get  all  the  feature  done  at  backend   •  The  Snippet  logic  makes  much  more  sense   than  MVC  for  me.  (although  I  love  django  too)   •  API  so  easy,  no  much  code  needed   32!
  • 33. Why I hate Lift! •  It’s  really  hard  to  get  HTML/XML  out  of  snippet   code.   •  Learning  curve  is  s9ff  if  you  are  not  used  to  its   logic.   •  Try  s9ck  to  the  latest  version.   •  Too  many  ways  to  write  it.   33!
  • 34. Free Books! •  Exploring  LiE:  exploring.liEweb.net   •  Simply  LiE:  simply.liEweb.net   •  LiE  Cookbook:  cookbook.liEweb.net   34!
  • 35. References! •  David  Pollak  On  LiE  Framework  and  Scala   www.infoq.com/interviews/LiE-­‐Scala-­‐David-­‐ Pollak   •  Example  &  Demo  Site:  demo.liEweb.net   •  Start  Up  Project  with  Maven:   www.assembla.com/wiki/show/liEweb/ Using_Maven   35!
  • 36. Get to me! •  Email:  wisnton@fliptop.com   •  URLs:   –  hMp://www.repfans.com/profile/33335/Winston %20Chen   –  hMp://careers.stackoverflow.com/wingchen   36!
  • 37. The last Q&A! Winston!
  • 38. Model! •  Mapper  or  Record   •  Take  a  look  at  here:   stackoverflow.com/ques9ons/6564332/when-­‐ to-­‐use-­‐mapper-­‐or-­‐record-­‐in-­‐liE   38!
  • 39. Menu Configurations! •  stackoverflow.com/ques9ons/2175246/ liEweb-­‐menu-­‐customiza9on   39!