SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
Enhancing Spring MVC
Web Applications with
Spring JavaScript
Jeremy Grelle - SpringSource
Slide Title




   In this session, you will learn how Spring JavaScript
   makes it simple to integrate rich Ajax toolkits such
   as Dojo into a Spring Web application to create
   compelling user interfaces.




                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Introduction

• Who am I???
  – Jeremy Grelle
     • Senior Software Engineer, SpringSource
     • Member of Spring Web Products team in San
       Francisco, CA
     • Lead of Spring Faces, Spring JavaScript, Spring
       BlazeDS Integration
     • JSF 2.0 EG member.
     • SpringSource's resident Ajax ninja.
     • Rock Star / Geek




                                                                                                 3
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Topics in this session

•   Overview of Ajax
•   Introduction to Spring JS
•   Spring JS Building Blocks
•   Spring JS Advanced Solutions
•   Spring JS + RESTful MVC




                                                                                                 4
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
What is Ajax?

• An ever-evolving definition

• Philosophy of User Experience

• Search for the right balance between client and
  server

• AJAX != Ajax




                                                                                                5
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The Building Blocks of Ajax

• Document Object Model (DOM)
  – tree HTML representation
  – easy to target parts of dynamic web page
  – e.g. 'disable all fields within a div'
• Cascading Stylesheets (CSS)
  – separates content (HTML) from style
  – CSS selectors apply style across DOM elements
• XMLHttpRequest
  – JavaScript API for asynchronous requests
• JavaScript Object Notation (JSON)



                                                                                               6
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Different Ajax Approaches

• JavaScript toolkit
  – Dojo, YUI, jQuery
• JavaScript wrapped
  – in JSF components (ICEfaces, RichFaces)
  – in JSP custom tags (AjaxTags)
• JavaScript generated
  – GWT
• JavaScript RPC-style invocations
  – DWR, JSON-RPC
• RIA - Not necessarily based on JavaScript



                                                                                               7
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Different Kinds of Frameworks

• Lightweight libraries
  – jQuery, Prototype, Scriptaculous

• Full solution frameworks
  – Dojo, YUI, Ext, GWT




                                                                                                8
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Different Application Types

• Applications based on browsing model
    – document-like, bookmarks, back button, refresh
    – example: infoq.com

 • Very rich applications in a browser
    – desktop style, window panes, menus
    – example: Google Maps, Bespin

 • Many applications somewhere in between
    – finding the right balance is important




                                                                                                  9
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The User Experience

• Ajax can do pretty “cool” things
  – it's easy to be awed at first BUT...
  – harder to predict the overall experience
• Consider the following “disruptive” effects
  – back/forward button
  – bookmarking
  – JavaScript turned off
  – support for accessibility features
• It's necessary to be pragmatic in using Ajax
  techniques
  – find the right blend of document-based vs. rich client



                                                                                                  10
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Ajax and Server-Side
Frameworks
• Ajax agnostic to server-side framework
    – plain HTTP request

 • The response is the contract
    – HTML (partial DOM update), JSON, XML, ...

 • Full HTML still required even for RIA
    – login page, help pages, ...




                                                                                                  11
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Spring MVC with Ajax

 • A swiss army knife for Web developers
  – very flexible, pluggable

 • Well-suited to handle Ajax requests
  – supports many rendering technologies
  – easy to expose HTTP endpoints
  – RESTful architecture is an ideal Ajax back-end

 • Versatility truly matters here!




                                                                                                12
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Topics in this session

•   Overview of Ajax
•   Introduction to Spring JS
•   Spring JS Building Blocks
•   Spring JS Advanced Solutions
•   Spring JS + RESTful MVC




                                                                                                 13
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Spring JavaScript Overview

• JavaScript abstraction framework
    – builds on existing toolkits
    – introduced as a SWF 2 module, moving to top-level
      project for 2010

 • Public API with implementations
    – currently Dojo
    – others possible (jQuery next)

 • A pragmatic approach
    – baked-in performance (Yahoo guidelines)
    – progressive enhancement

                                                                                                  14
                 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Progressive Enhancement
(client side)

• Add Ajax behavior unobtrusively
  – avoid proliferation of JavaScript

• Manipulate DOM nodes
  – “enhance” plain HTML elements

• Page functions with or without JavaScript




                                                                                                15
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Progressive Enhancement
(server side)

• Avoid separate controllers for Ajax
  – use same request handling methods

• Render a page partially
  – composition-based template approach

• Alternate response types
  – HTML, JSON, XML, ...




                                                                                               16
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The Parts of Spring JS

• JavaScript libraries
  – public API + implementations
• Bundled (optimized) toolkits
  – currently Dojo 1.2
• “Starter” CSS framework
  – Mike Stenhouse's CSS framework
• ResourceServlet
  – efficient rendering of static resources in a war or
  a jar
• Spring MVC infrastructure for Ajax
  – AjaxUrlBasedViewResolver, AjaxTilesView, ...

                                                                                                17
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The ResourceServlet

• Generic servlet to serve static resources
  – .js, .css, .jpeg, .gif, etc.

• Locates resources given the path info
  – first under the Web application root
  – the classpath as a fall back

• Writes the resource to the HTTP response
  – gzip compression
  – set response headers: last modified, content
  type, ...


                                                                                                18
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Serving Spring JS Files

 • Spring JS distributed as a jar
      – bundles JavaScript, CSS, and other resources
 • Serve them with the ResourceServlet
 • Possible to override bundled resources
      – include your own in the webapp root
<servlet>
 <servlet-name>Resources Servlet</servlet-name>
 <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
 <servlet-name>Resources Servlet</servlet-name>
 <url-pattern>/resources/*</url-pattern>
</servlet-mapping>

                                                                                                         19
                        SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Spring JS Resources

• Underlying library
  – /resources/dojo/dojo.js

• Public API
  – /resources/spring/Spring.js

• Toolkit-specific implementation
  – /resources/spring/Spring-Dojo.js

• Additional underlying library resources
  – /resources/dijit/themes/tundra/tundra.css


                                                                                                20
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Including Spring JS On a Page

 • Include required files
<link type="text/css" rel="stylesheet"
   href="<c:url value="/resources/dijit/themes/tundra/tundra.css" />" />

<script type="text/javascript"
          src ="<c:url value="/resources/dojo/dojo.js" />"><script/>
<script type="text/javascript"
          src ="<c:url value="/resources/spring/Spring.js" />"><script/>
<script type="text/javascript"
          src ="<c:url value="/resources/spring/Spring-Dojo.js" />"><script/>

 • Add Dojo “tundra” style to body tag
<body class="tundra" > ...



                                                                                                          21
                         SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Topics in this session

•   Overview of Ajax
•   Introduction to Spring JS
•   Spring JS Building Blocks
•   Spring JS Advanced Solutions
•   Spring JS + RESTful MVC




                                                                                                 22
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Enhancing a DOM Node

• DOM nodes can be manipulated
  – decorate with new look and/or behavior
  – via JS and CSS

• A common technique for “enhancing” plain HTML
  – separates static from dynamic parts
  – easier to understand & maintain

• Supported by underlying toolkit
  – e.g. turn HTML form fields to rich widgets



                                                                                                23
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Spring JS Decorations

• Mechanism for DOM node enhancements
  – abstracts underlying toolkit

• A function for applying decorations
  – Spring.addDecoration(/*Object*/decoration)

• Several available decorations
  – Element decoration
  – Ajax event decoration
  – Validate All decoration



                                                                                                24
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Fragment Rendering

• An Ajax call refreshes parts of a page
  – response must contain a “fragment”
  – not HTML for entire page

• Yet controllers should not be aware of Ajax
  – easier to maintain that way

• Spring JS provides special Spring MVC view
  – renders a fragment of the response only
  – works transparently



                                                                                                25
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The “Fragments” Parameter

• Ajax event decoration submits special parameter
  – a hint for what HTML to be rendered

• Server notices special parameter
  – renders only specified fragment

• Composition-based view technology is required
  – currently JSP/Tiles supported only
  – fragment names match to a Tiles attribute




                                                                                                26
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Built-In Response Handling
Types
• Refresh portions of the page
   – grab top-level DOM nodes
   – replace equivalent nodes on existing page

• Present Ajax popup
   – a modal dialog with the returned HTML
   – enable via AjaxEventDecoration “popup” attribute

• Client side redirect
   – detects server response requesting client-side
     redirect
   – requires AjaxUrlBasedViewResolver


                                                                                                 27
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Demo
Spring JS Building Blocks




       SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Topics in this session

•   Overview of Ajax
•   Introduction to Spring JS
•   Spring JS Building Blocks
•   Spring JS Advanced Solutions
•   Spring JS + RESTful MVC




                                                                                                29
               SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Common Questions

• The fundamental pieces of Spring JS seem nice,
  but how do I...

  – perform custom response handling?

  – make my code more terse?

  – keep things DRY?

  – organize and modularize my growing amount of
    JavaScript code?


                                                                                               30
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Demo
Spring JS Advanced Solutions




       SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Topics in this session

•   Overview of Ajax
•   Introduction to Spring JS
•   Spring JS Building Blocks
•   Spring JS Advanced Solutions
•   Spring JS + RESTful MVC




                                                                                                 32
                SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
The Evolving Web Platform

• Capable browsers with advanced JavaScript VM’s
  are becoming more commonplace
  – Safari, Firefox, and Chrome
  – Webkit-based mobile browsers

• As the platform evolves, boundaries can be pushed
  further on the client
  – see Canvas, SVG, Video in HTML 5

• RESTful services provide the perfect compliment
  on the server-side
  – JSON representations easy to consume

                                                                                               33
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
JSON support in Spring 3.0

• MappingJacksonJsonView
  – renders the model as JSON
  – customizable via annotations
  – high-performance

• MappingJacksonHttpMessageConverter
  – easy binding from a JSON payload




                                                                                               34
              SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Demo
Consuming RESTful Services




      SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Summary

• Spring MVC very useful for Ajax
  – a swiss-army knife

• Spring JS provides simple abstraction
  – builds on existing Ajax toolkits
  – provides both client and server side components

• Many common enterprise scenarios made easy
  – rich forms
  – partial page updates
  – Ajax popups
  – JSON

                                                                                                   36
                  SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
Q&A




      SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.

Más contenido relacionado

La actualidad más candente

Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
Jussi Pohjolainen
 
Oxford DrupalCamp 2012 - The things we found in your website
Oxford DrupalCamp 2012 - The things we found in your websiteOxford DrupalCamp 2012 - The things we found in your website
Oxford DrupalCamp 2012 - The things we found in your website
hernanibf
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
hernanibf
 
My site is slow
My site is slowMy site is slow
My site is slow
hernanibf
 

La actualidad más candente (19)

新版阿尔法城背后的前端MVC实践
新版阿尔法城背后的前端MVC实践新版阿尔法城背后的前端MVC实践
新版阿尔法城背后的前端MVC实践
 
Santosh_Resume_Java
Santosh_Resume_JavaSantosh_Resume_Java
Santosh_Resume_Java
 
Intro to Java ME and Asha Platform
Intro to Java ME and Asha PlatformIntro to Java ME and Asha Platform
Intro to Java ME and Asha Platform
 
Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012Single Page Applications - Desert Code Camp 2012
Single Page Applications - Desert Code Camp 2012
 
The Modern Java Web Developer - JavaOne 2013
The Modern Java Web Developer - JavaOne 2013The Modern Java Web Developer - JavaOne 2013
The Modern Java Web Developer - JavaOne 2013
 
Intro to drupal
Intro to drupalIntro to drupal
Intro to drupal
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
2013 04-02-server-side-backbone
2013 04-02-server-side-backbone2013 04-02-server-side-backbone
2013 04-02-server-side-backbone
 
Oxford DrupalCamp 2012 - The things we found in your website
Oxford DrupalCamp 2012 - The things we found in your websiteOxford DrupalCamp 2012 - The things we found in your website
Oxford DrupalCamp 2012 - The things we found in your website
 
One Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp LondonOne Drupal to rule them all - Drupalcamp London
One Drupal to rule them all - Drupalcamp London
 
Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010Comparing JVM Web Frameworks - Devoxx 2010
Comparing JVM Web Frameworks - Devoxx 2010
 
Next generation Graphics: SVG
Next generation Graphics: SVGNext generation Graphics: SVG
Next generation Graphics: SVG
 
Front End page speed performance improvements for Drupal
Front End page speed performance improvements for DrupalFront End page speed performance improvements for Drupal
Front End page speed performance improvements for Drupal
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
 
My site is slow
My site is slowMy site is slow
My site is slow
 
Drupal - Introduction to Building Library Web Site Using Drupal
Drupal - Introduction to Building Library Web Site Using DrupalDrupal - Introduction to Building Library Web Site Using Drupal
Drupal - Introduction to Building Library Web Site Using Drupal
 
jQuery Comes to XPages
jQuery Comes to XPagesjQuery Comes to XPages
jQuery Comes to XPages
 
Devfest09 Cschalk Gwt
Devfest09 Cschalk GwtDevfest09 Cschalk Gwt
Devfest09 Cschalk Gwt
 
Building and Managing Projects with Maven
Building and Managing Projects with MavenBuilding and Managing Projects with Maven
Building and Managing Projects with Maven
 

Destacado

Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
martinlippert
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
Tuna Tore
 
Hr coverage directi 2012
Hr coverage directi 2012Hr coverage directi 2012
Hr coverage directi 2012
Directi Group
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
Chamnap Chhorn
 
Architecture of a Modern Web App
Architecture of a Modern Web AppArchitecture of a Modern Web App
Architecture of a Modern Web App
scothis
 

Destacado (10)

Modern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScriptModern Architectures with Spring and JavaScript
Modern Architectures with Spring and JavaScript
 
Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC Design & Development of Web Applications using SpringMVC
Design & Development of Web Applications using SpringMVC
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
Building a Scalable Architecture for web apps
Building a Scalable Architecture for web appsBuilding a Scalable Architecture for web apps
Building a Scalable Architecture for web apps
 
Hr coverage directi 2012
Hr coverage directi 2012Hr coverage directi 2012
Hr coverage directi 2012
 
Web Application Development Fundamentals
Web Application Development FundamentalsWeb Application Development Fundamentals
Web Application Development Fundamentals
 
Web application architecture
Web application architectureWeb application architecture
Web application architecture
 
Introduction to Web Architecture
Introduction to Web ArchitectureIntroduction to Web Architecture
Introduction to Web Architecture
 
Fundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-DevelopersFundamentals of Web Development For Non-Developers
Fundamentals of Web Development For Non-Developers
 
Architecture of a Modern Web App
Architecture of a Modern Web AppArchitecture of a Modern Web App
Architecture of a Modern Web App
 

Similar a Enhancing Spring MVC Web Applications Progressively with Spring JavaScript

Structured web apps
Structured web appsStructured web apps
Structured web apps
Sheng Tian
 
WebNetConf 2012 - Single Page Apps
WebNetConf 2012 - Single Page AppsWebNetConf 2012 - Single Page Apps
WebNetConf 2012 - Single Page Apps
Pop Apps
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
rajivmordani
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
jbandi
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
Andrew Ferrier
 
01/2009 - Portral development with liferay
01/2009 - Portral development with liferay01/2009 - Portral development with liferay
01/2009 - Portral development with liferay
daveayan
 

Similar a Enhancing Spring MVC Web Applications Progressively with Spring JavaScript (20)

Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
An introduction to Node.js
An introduction to Node.jsAn introduction to Node.js
An introduction to Node.js
 
JavaScript-Core
JavaScript-CoreJavaScript-Core
JavaScript-Core
 
Structured web apps
Structured web appsStructured web apps
Structured web apps
 
Building assets on the fly with Node.js
Building assets on the fly with Node.jsBuilding assets on the fly with Node.js
Building assets on the fly with Node.js
 
The Java alternative to Javascript
The Java alternative to JavascriptThe Java alternative to Javascript
The Java alternative to Javascript
 
Going offline with JS (DDD Sydney)
Going offline with JS (DDD Sydney)Going offline with JS (DDD Sydney)
Going offline with JS (DDD Sydney)
 
AJAX Frameworks
AJAX FrameworksAJAX Frameworks
AJAX Frameworks
 
Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech People
 
AngularJS - Architecture decisions in a large project 
AngularJS - Architecture decisionsin a large project AngularJS - Architecture decisionsin a large project 
AngularJS - Architecture decisions in a large project 
 
Progressive Web Apps and React
Progressive Web Apps and ReactProgressive Web Apps and React
Progressive Web Apps and React
 
An evening with React Native
An evening with React NativeAn evening with React Native
An evening with React Native
 
WebNetConf 2012 - Single Page Apps
WebNetConf 2012 - Single Page AppsWebNetConf 2012 - Single Page Apps
WebNetConf 2012 - Single Page Apps
 
Server Side Javascript
Server Side JavascriptServer Side Javascript
Server Side Javascript
 
Kann JavaScript elegant sein?
Kann JavaScript elegant sein?Kann JavaScript elegant sein?
Kann JavaScript elegant sein?
 
Going Offline with JS
Going Offline with JSGoing Offline with JS
Going Offline with JS
 
Mobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best PracticesMobile and IBM Worklight Best Practices
Mobile and IBM Worklight Best Practices
 
01/2009 - Portral development with liferay
01/2009 - Portral development with liferay01/2009 - Portral development with liferay
01/2009 - Portral development with liferay
 
Javascript & Jquery
Javascript & JqueryJavascript & Jquery
Javascript & Jquery
 
GWT-Basics
GWT-BasicsGWT-Basics
GWT-Basics
 

Último

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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

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
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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
 
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
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Enhancing Spring MVC Web Applications Progressively with Spring JavaScript

  • 1. Enhancing Spring MVC Web Applications with Spring JavaScript Jeremy Grelle - SpringSource
  • 2. Slide Title In this session, you will learn how Spring JavaScript makes it simple to integrate rich Ajax toolkits such as Dojo into a Spring Web application to create compelling user interfaces. SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 3. Introduction • Who am I??? – Jeremy Grelle • Senior Software Engineer, SpringSource • Member of Spring Web Products team in San Francisco, CA • Lead of Spring Faces, Spring JavaScript, Spring BlazeDS Integration • JSF 2.0 EG member. • SpringSource's resident Ajax ninja. • Rock Star / Geek 3 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 4. Topics in this session • Overview of Ajax • Introduction to Spring JS • Spring JS Building Blocks • Spring JS Advanced Solutions • Spring JS + RESTful MVC 4 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 5. What is Ajax? • An ever-evolving definition • Philosophy of User Experience • Search for the right balance between client and server • AJAX != Ajax 5 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 6. The Building Blocks of Ajax • Document Object Model (DOM) – tree HTML representation – easy to target parts of dynamic web page – e.g. 'disable all fields within a div' • Cascading Stylesheets (CSS) – separates content (HTML) from style – CSS selectors apply style across DOM elements • XMLHttpRequest – JavaScript API for asynchronous requests • JavaScript Object Notation (JSON) 6 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 7. Different Ajax Approaches • JavaScript toolkit – Dojo, YUI, jQuery • JavaScript wrapped – in JSF components (ICEfaces, RichFaces) – in JSP custom tags (AjaxTags) • JavaScript generated – GWT • JavaScript RPC-style invocations – DWR, JSON-RPC • RIA - Not necessarily based on JavaScript 7 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 8. Different Kinds of Frameworks • Lightweight libraries – jQuery, Prototype, Scriptaculous • Full solution frameworks – Dojo, YUI, Ext, GWT 8 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 9. Different Application Types • Applications based on browsing model – document-like, bookmarks, back button, refresh – example: infoq.com • Very rich applications in a browser – desktop style, window panes, menus – example: Google Maps, Bespin • Many applications somewhere in between – finding the right balance is important 9 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 10. The User Experience • Ajax can do pretty “cool” things – it's easy to be awed at first BUT... – harder to predict the overall experience • Consider the following “disruptive” effects – back/forward button – bookmarking – JavaScript turned off – support for accessibility features • It's necessary to be pragmatic in using Ajax techniques – find the right blend of document-based vs. rich client 10 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 11. Ajax and Server-Side Frameworks • Ajax agnostic to server-side framework – plain HTTP request • The response is the contract – HTML (partial DOM update), JSON, XML, ... • Full HTML still required even for RIA – login page, help pages, ... 11 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 12. Spring MVC with Ajax • A swiss army knife for Web developers – very flexible, pluggable • Well-suited to handle Ajax requests – supports many rendering technologies – easy to expose HTTP endpoints – RESTful architecture is an ideal Ajax back-end • Versatility truly matters here! 12 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 13. Topics in this session • Overview of Ajax • Introduction to Spring JS • Spring JS Building Blocks • Spring JS Advanced Solutions • Spring JS + RESTful MVC 13 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 14. Spring JavaScript Overview • JavaScript abstraction framework – builds on existing toolkits – introduced as a SWF 2 module, moving to top-level project for 2010 • Public API with implementations – currently Dojo – others possible (jQuery next) • A pragmatic approach – baked-in performance (Yahoo guidelines) – progressive enhancement 14 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 15. Progressive Enhancement (client side) • Add Ajax behavior unobtrusively – avoid proliferation of JavaScript • Manipulate DOM nodes – “enhance” plain HTML elements • Page functions with or without JavaScript 15 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 16. Progressive Enhancement (server side) • Avoid separate controllers for Ajax – use same request handling methods • Render a page partially – composition-based template approach • Alternate response types – HTML, JSON, XML, ... 16 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 17. The Parts of Spring JS • JavaScript libraries – public API + implementations • Bundled (optimized) toolkits – currently Dojo 1.2 • “Starter” CSS framework – Mike Stenhouse's CSS framework • ResourceServlet – efficient rendering of static resources in a war or a jar • Spring MVC infrastructure for Ajax – AjaxUrlBasedViewResolver, AjaxTilesView, ... 17 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 18. The ResourceServlet • Generic servlet to serve static resources – .js, .css, .jpeg, .gif, etc. • Locates resources given the path info – first under the Web application root – the classpath as a fall back • Writes the resource to the HTTP response – gzip compression – set response headers: last modified, content type, ... 18 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 19. Serving Spring JS Files • Spring JS distributed as a jar – bundles JavaScript, CSS, and other resources • Serve them with the ResourceServlet • Possible to override bundled resources – include your own in the webapp root <servlet> <servlet-name>Resources Servlet</servlet-name> <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Resources Servlet</servlet-name> <url-pattern>/resources/*</url-pattern> </servlet-mapping> 19 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 20. Spring JS Resources • Underlying library – /resources/dojo/dojo.js • Public API – /resources/spring/Spring.js • Toolkit-specific implementation – /resources/spring/Spring-Dojo.js • Additional underlying library resources – /resources/dijit/themes/tundra/tundra.css 20 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 21. Including Spring JS On a Page • Include required files <link type="text/css" rel="stylesheet" href="<c:url value="/resources/dijit/themes/tundra/tundra.css" />" /> <script type="text/javascript" src ="<c:url value="/resources/dojo/dojo.js" />"><script/> <script type="text/javascript" src ="<c:url value="/resources/spring/Spring.js" />"><script/> <script type="text/javascript" src ="<c:url value="/resources/spring/Spring-Dojo.js" />"><script/> • Add Dojo “tundra” style to body tag <body class="tundra" > ... 21 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 22. Topics in this session • Overview of Ajax • Introduction to Spring JS • Spring JS Building Blocks • Spring JS Advanced Solutions • Spring JS + RESTful MVC 22 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 23. Enhancing a DOM Node • DOM nodes can be manipulated – decorate with new look and/or behavior – via JS and CSS • A common technique for “enhancing” plain HTML – separates static from dynamic parts – easier to understand & maintain • Supported by underlying toolkit – e.g. turn HTML form fields to rich widgets 23 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 24. Spring JS Decorations • Mechanism for DOM node enhancements – abstracts underlying toolkit • A function for applying decorations – Spring.addDecoration(/*Object*/decoration) • Several available decorations – Element decoration – Ajax event decoration – Validate All decoration 24 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 25. Fragment Rendering • An Ajax call refreshes parts of a page – response must contain a “fragment” – not HTML for entire page • Yet controllers should not be aware of Ajax – easier to maintain that way • Spring JS provides special Spring MVC view – renders a fragment of the response only – works transparently 25 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 26. The “Fragments” Parameter • Ajax event decoration submits special parameter – a hint for what HTML to be rendered • Server notices special parameter – renders only specified fragment • Composition-based view technology is required – currently JSP/Tiles supported only – fragment names match to a Tiles attribute 26 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 27. Built-In Response Handling Types • Refresh portions of the page – grab top-level DOM nodes – replace equivalent nodes on existing page • Present Ajax popup – a modal dialog with the returned HTML – enable via AjaxEventDecoration “popup” attribute • Client side redirect – detects server response requesting client-side redirect – requires AjaxUrlBasedViewResolver 27 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 28. Demo Spring JS Building Blocks SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 29. Topics in this session • Overview of Ajax • Introduction to Spring JS • Spring JS Building Blocks • Spring JS Advanced Solutions • Spring JS + RESTful MVC 29 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 30. Common Questions • The fundamental pieces of Spring JS seem nice, but how do I... – perform custom response handling? – make my code more terse? – keep things DRY? – organize and modularize my growing amount of JavaScript code? 30 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 31. Demo Spring JS Advanced Solutions SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 32. Topics in this session • Overview of Ajax • Introduction to Spring JS • Spring JS Building Blocks • Spring JS Advanced Solutions • Spring JS + RESTful MVC 32 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 33. The Evolving Web Platform • Capable browsers with advanced JavaScript VM’s are becoming more commonplace – Safari, Firefox, and Chrome – Webkit-based mobile browsers • As the platform evolves, boundaries can be pushed further on the client – see Canvas, SVG, Video in HTML 5 • RESTful services provide the perfect compliment on the server-side – JSON representations easy to consume 33 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 34. JSON support in Spring 3.0 • MappingJacksonJsonView – renders the model as JSON – customizable via annotations – high-performance • MappingJacksonHttpMessageConverter – easy binding from a JSON payload 34 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 35. Demo Consuming RESTful Services SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 36. Summary • Spring MVC very useful for Ajax – a swiss-army knife • Spring JS provides simple abstraction – builds on existing Ajax toolkits – provides both client and server side components • Many common enterprise scenarios made easy – rich forms – partial page updates – Ajax popups – JSON 36 SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.
  • 37. Q&A SpringOne 2GX 2009. All rights reserved. Do not distribute without permission.