Ajax Integration Guide

  • 3,297 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,297
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
98
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Ajax Integration Guide for Spring Enterprise Applications Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 1
  • 2. Introduction • Who am I??? – Jeremy Grelle • Senior Software Engineer, SpringSource • Member of Spring Web Products team in Melbourne, FL. • Lead of Spring Faces, Spring JavaScript, JSF 2.0 EG member. • SpringSource's resident RIA ninja. • Rock Star / Geek Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2 2
  • 3. Our Open Source Projects Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3 3
  • 4. Spring Uptake Cumulative downloads (Sourceforge-only) 3,000,000 2,250,000 1,500,000 750,000 0 11/1/03 1/1/08 8/1/07 3/1/07 10/1/06 5/1/06 12/1/05 7/1/05 2/1/05 9/1/04 4/1/04 64% of enterprises using Spring source: BEA dev2dev survey Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4 4
  • 5. Our Commercial Products Spring SpringSource Enterprise Performance Edition Suite SpringSource Enterprise SpringSource Support Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5 5
  • 6. Application Server Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6 6
  • 7. Topics • A Plethora of Choices – JavaScript libraries – JSF components – RIA remoting • Approaches to integration with Spring – Spring JavaScript – Spring Faces – Spring MVC – RESTful @Controller – Spring Flex? Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7 7
  • 8. The State of Ajax Today • Too much choice? Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8 8
  • 9. How Do We Choose a JavaScript Library??? • Important Features: – Ease of use / Quality of documentation – Supports unobtrusive use / progressive enhancement – Support for accessibility – Consistent cross-browser support – Vibrant community – Optimized for good performance – Easy to integrate with Java / Spring Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9 9
  • 10. The Cream Is Rising... • The major players that are starting to seperate themselves from the rest: – Prototype / Scriptaculous – jQuery – YUI – Ext – Dojo Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10 10
  • 11. Dojo – Our First Choice • A complete framework that combines the low-level utility of Prototype / jQuery with an extensive collection of UI widgets. • A modular packaging system that allows you to “import” other modules, similar to Java's package system. • Pioneering support for accessibility in their widget system – ARIA Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11 11
  • 12. Commonalities • All of these frameworks are about more than just the asynchronous exchange of data with the server. • They all focus on improving the quality of your client-side code and enabling you to bring a better experience to your users. • They are all able to be used in an unobtrusive manner to provide a progressively enhanced UI – Requires careful design. Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12 12
  • 13. Connecting to Spring • There are a number of effective techniques available for connecting your Ajax-enhanced UI to take advantage of Spring-based server-side resources • It is important to strike the right balance between processing on the client and processing on the server. Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13 13
  • 14. The Progressive Approach • Ideally take advantage of the existing controller infrastructure. • We want to have an application that is able to maintain the same functionality without Ajax as it does with Ajax. – Progressively enhanced – Focus on accessibility Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14 14
  • 15. Spring Web Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15 11 15
  • 16. Spring JavaScript • New module introduced in the Web Flow 2 Distribution • JavaScript abstraction framework that allows you to progressively enhance a web page with behavior – Consists of a public .js API and implementation • Builds on Dojo, other implementations possible (jQuery probably next) • Handle the 80% case, while not hiding the underlying library • API can be used directly, or used by a tag lib Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12 16 16
  • 17. Spring JavaScript • Focus on progressive enhancement – A more pragmatic approach than full RIA • Support for partial fragment rendering from Spring MVC through AjaxTilesView • Dojo (optimized build) and CSS Framework packaged for convenience and served by the ResourceServlet – Yahoo performance guidelines baked in Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13 17 17
  • 18. Element Decoration Example <form:input path=quot;creditCardNumberquot;/> <script type=quot;text/javascriptquot;> Spring.addDecoration(new Spring.ElementDecoration({ elementId : quot;creditCardNumberquot;, widgetType : quot;dijit.form.ValidationTextBoxquot;, widgetAttrs : { invalidMessage : quot;Invalid credit card number!quot;, regExp : quot;d{16}quot;, required : true } })); <script/> Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18 18
  • 19. AJAX Event Decoration Example • Link decoration <a id=quot;nextUrlquot; href=quot;...quot;>Next Page</a> <script type=quot;text/javascriptquot;> Spring.addDecoration(new Spring.AjaxEventDecoration({ elementId : quot;nextUrlquot;, event : quot;onclickquot; })); </script> Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19 19
  • 20. Spring Booking-MVC Code Examples and Demo Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20 20
  • 21. JSF - Another level of abstraction... • JSF components can provide another level of abstraction to allow you to add Ajax functionality in a more declarative manner. – Established libraries such as ICEFaces and Ajax4JSF – Spring Faces • Aims to ease the integration burden by being compatible with leading Javascript frameworks. • Builds on Spring JS Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21 21
  • 22. Spring Faces Code Examples and Demo Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 22 22
  • 23. RESTful Spring • REST is an important piece of the evolving Spring Web ecosystem. – Central theme in Spring 3.0 • Provide different representations of the same resource. – HTML for full page display or partial DOM update. – JSON for intelligent widgets such as the Dojo table widget. • dojo.data – Any content type is possible Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 23 23
  • 24. RESTful @Controller @RequestMapping(value=quot;/hotelsquot;, method=RequestMethod.GET) public String getHotels(ModelMap model) { List<Hotel> hotels = hotelService.getHotels(); model.addAttribute(quot;hotelsquot;, hotels); return quot;hotelsquot;; } @RequestMapping(value=quot;/hotels/{hotel}quot;, method=RequestMethod.PUT)‫‏‬ public void updateHotel(@UriParam(quot;hotelquot;)long id, Hotel hotel) { hotelService.updateHotel(id, hotel); } @RequestMapping(value=quot;/hotels/{hotel}/bookings/{booking}quot;, method=RequestMethod.GET) public String getBooking(@UriParam(quot;hotelquot;)long hotelId, @UriParam(quot;bookingquot;)long bookingId, ModelMap model) { Hotel hotel = hotelService.getHotel(hotelId); Booking booking = hotel.getBooking(bookingId); model.addAttribute(quot;bookingquot;, booking); return quot;bookingquot;; } @RequestMapping(value=quot;/hotels/{hotel}/bookingsquot;, method=RequestMethod.POST)‫‏‬ public void addBooking(@UriParam(quot;hotelquot;)long hotelId, Booking booking) { // store booking } Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 24 24
  • 25. RESTful Spring Code Examples and Demo Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 25 25
  • 26. RIA Remoting - Spring Flex? • Basic approaches to integration available now – Adobe's BlazeDS and LiveCycle Data Services – GraniteDS • Would be interesting to reduce the conceptual overhead – Reduce configuration required – Expose Spring beans directly • Prototyping deeper BlazeDS integration for the Spring 3.0 timeframe Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 26 26
  • 27. Spring Flex? Code Examples and Demo Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 27 27
  • 28. Summary • Spring has always emphasized choice – No different with Ajax and RIA – Same Spring service infrastructure for any client type • Spring MVC's flexible infrastructure makes it well-suited to Ajax and RIA • Choose the client-side technology based on merit and fit for application requirements Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 28 28
  • 29. Resources • Spring Framework and Spring Web Flow distros: http://www.springframework.org/downloads • Dojo http://www.dojotoolkit.org • Adobe BlazeDS http://opensource.adobe.com/wiki/display/blazeds/BlazeDS/ Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 29 29