Скачать презентацию Developing Rich Web Applications with Spring Keith Donald Скачать презентацию Developing Rich Web Applications with Spring Keith Donald

3b18b6f2980bd97af6dfffb699e074b9.ppt

  • Количество слайдов: 55

Developing Rich Web Applications with Spring Keith Donald Copyright 2008 Spring. Source. Copying, publishing Developing Rich Web Applications with Spring Keith Donald Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Agenda • A little bit about your speaker • Developing rich web applications – Agenda • A little bit about your speaker • Developing rich web applications – Programming model – Convention-over-configuration – Ajax – Flow – Security – Java. Server. Faces – Better modularity with OSGi Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 2

My Background • Spring. Source Co-Founder – Based in Melbourne Florida • Application Developer My Background • Spring. Source Co-Founder – Based in Melbourne Florida • Application Developer • Spring Project Lead • Author – Several Spring books – Spring Training Curriculum • Conference Director, The Spring Experience • Java. One and NFJS Speaker • JCP Expert Group Member Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 3

Where I Work Copyright 2008 Spring. Source. Copying, publishing or distributing without express written Where I Work Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 4

Our Open Source Projects Copyright 2008 Spring. Source. Copying, publishing or distributing without express Our Open Source Projects Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 5

Our Commercial Products Spring. Source Performance Suite Spring Enterprise Edition Spring. Source Enterprise Spring. Our Commercial Products Spring. Source Performance Suite Spring Enterprise Edition Spring. Source Enterprise Spring. Source Support Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 6

Spring. Source Enterprise STS AMS RAC Copyright 2008 Spring. Source. Copying, publishing or distributing Spring. Source Enterprise STS AMS RAC Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 7

Spring. Source dm Server™ Copyright 2008 Spring. Source. Copying, publishing or distributing without express Spring. Source dm Server™ Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 8

Agenda • A little bit about your speakers • Developing rich web applications – Agenda • A little bit about your speakers • Developing rich web applications – Programming model – Convention-over-configuration – Ajax – Flow – Security – Java. Server. Faces Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 9

Modules Covered • Spring Web MVC – foundation for all other web modules • Modules Covered • Spring Web MVC – foundation for all other web modules • Spring Java. Script – Ajax support • Spring Web Flow – framework for stateful interactions • Spring Faces – Java. Server Faces support Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 10

Layered Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web MVC Layered Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web MVC Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 11

Obtaining Code • See www. springframework. org/download • Web MVC – Download Spring Framework Obtaining Code • See www. springframework. org/download • Web MVC – Download Spring Framework 2. 5. x • Java. Script, Web Flow, and Faces – Download Spring Web Flow 2. 0. x • Sample Application – See www. springframework. org/webflow-samples Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 12

Spring Web MVC • Popular web framework • Foundation for all other web modules Spring Web MVC • Popular web framework • Foundation for all other web modules • Significantly enhanced in Spring 2. 5 – Annotated controller model – Convention-over-configuration Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 13

Annotated Controller Model • Annotate a plain Java™ class as a Controller • Map Annotated Controller Model • Annotate a plain Java™ class as a Controller • Map HTTP requests to methods – Bind request parameters to method arguments – Populate Model to export data to the view – Return a String to select a view Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 14

Example • @Controller to manage hotels • GET /hotels/list – List hotels available for Example • @Controller to manage hotels • GET /hotels/list – List hotels available for booking Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 15

Example @Controller public class Hotels. Controller { @Request. Mapping(“/hotels/list”, method=GET) public String list(Model model) Example @Controller public class Hotels. Controller { @Request. Mapping(“/hotels/list”, method=GET) public String list(Model model) { model. add(“hotels”, hotel. Service. find. All()); return “/hotels/list”; } } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 16

Example Request Lifecycle /hotels/list Dispatcher Servlet invoke /hotels/list Hotels. Controller. list(Model) render Model {hotels} Example Request Lifecycle /hotels/list Dispatcher Servlet invoke /hotels/list Hotels. Controller. list(Model) render Model {hotels} /hotels/list. jsp Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 17

Before Spring Web MVC 2. 5 public class Hotels. Controller extends Multi. Action. Controller Before Spring Web MVC 2. 5 public class Hotels. Controller extends Multi. Action. Controller { public Model. And. View list( Http. Servlet. Request request, Http. Servlet. Response response) { Model. And. View mv = new Model. And. View(); mv. add(“hotels”, hotel. Service. find. All()); mv. set. View. Name(“/hotels/list”); return mv; } } + External XML URL Mapping Configuration Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 18

Convention over configuration • Write less code, get consistency • Conventions available for – Convention over configuration • Write less code, get consistency • Conventions available for – Request mapping – View name selection – Model population • Can always override when needed Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 19

With Conventions GET /hotels/list @Controller public class Hotels. Controller { Mapping to class + With Conventions GET /hotels/list @Controller public class Hotels. Controller { Mapping to class + method name View @Request. Mapping selected public void list(Model model) { from model. add(hotel. Service. find. All()); request path } Model entry name generated from object type } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 20

Simplest Signature Possible @Controller public class Hotels. Controller { @Request. Mapping Added topublic List<Hotel> Simplest Signature Possible @Controller public class Hotels. Controller { @Request. Mapping Added topublic List list() { the Model return hotel. Service. find. All(); for you } } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 21

Multi-Action Convention Example @Controller public class Hotels. Controller { /hotels/index @Request. Mapping public void Multi-Action Convention Example @Controller public class Hotels. Controller { /hotels/index @Request. Mapping public void index(…) {…} /hotels/show @Request. Mapping public void show(…) {…} /hotels/update @Request. Mapping public void update(…) {…} } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 22

Data Binding @Controller public class Hotels. Controller { /hotels/list? search. String=Westin&page. Size=5 @Request. Mapping Data Binding @Controller public class Hotels. Controller { /hotels/list? search. String=Westin&page. Size=5 @Request. Mapping public void list(Criteria c, Model m) { model. add(hotel. Service. find(c)); } /hotels/show? id=1 @Request. Mapping public void show(@Request. Param Long id, Model m) { model. add(hotel. Service. get(id)); } } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 23

@Controller Deployment • Found in classpath • Auto-wired as Spring beans <!-- Scan for @Controller Deployment • Found in classpath • Auto-wired as Spring beans Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 24

Autowiring Hints @Controller public class Hotels. Controller { @Autowired public Hotels. Controller(Hotel. Service service) Autowiring Hints @Controller public class Hotels. Controller { @Autowired public Hotels. Controller(Hotel. Service service) { } } @Service public class Hibernate. Hotel. Service implements Hotel. Service { @Autowired public Hibernate. Hotel. Service(Data. Source ds) { } @Transactional public List find(Criteria c) {} } Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 25

Mixing Annotations and XML <beans> Configure your application beans <context: component-scan base-package=”example. hotels”/> Link Mixing Annotations and XML Configure your application beans Link with environment-specific infrastructure Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 26

Demo Essential Spring MVC Features Copyright 2008 Spring. Source. Copying, publishing or distributing without Demo Essential Spring MVC Features Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Web MVC Summary • Favor @Controller model over old styles • Favor convention-over-configuration • Web MVC Summary • Favor @Controller model over old styles • Favor convention-over-configuration • Favor strongly typed handler methods • Consider grouping control logic by Resource – e. g. “Hotels. Controller” for acting on Hotel resources Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 28

Spring Java. Script Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Java. Script Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web MVC Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 29

Spring Java. Script • Java. Script abstraction framework – Use to enhance HTML elements Spring Java. Script • Java. Script abstraction framework – Use to enhance HTML elements with behavior • Integrates the Dojo Toolkit • In Web Flow 2 distribution Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 30

Goals of Spring Java. Script • Simplify use of Dojo for common enterprise use Goals of Spring Java. Script • Simplify use of Dojo for common enterprise use cases – Ajax – Client-side validation • Promote progressive enhancement – Graceful degradation – Accessibility Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 31

Other Spring Java. Script Value Adds • Resource. Servlet – Efficient serving of static Other Spring Java. Script Value Adds • Resource. Servlet – Efficient serving of static resources – Meets Yahoo performance guidelines • CSS Framework – Structure for common page layouts Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 32

Using Spring Java. Script • Include public API, Dojo, and API implementation in your Using Spring Java. Script • Include public API, Dojo, and API implementation in your pages Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 33

Working with the API • Use API to apply decorations to HTML elements • Working with the API • Use API to apply decorations to HTML elements • Different types of decorations – Widget. Decoration – Ajax. Event. Decoration – Validate. All. Decoration Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 34

Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 35

More Results" src="https://present5.com/presentation/3b18b6f2980bd97af6dfffb699e074b9/image-36.jpg" alt="Ajax with Partial Rendering More Results" /> Ajax with Partial Rendering More Results No callback function necessary to link in response Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 36

Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 37

Combining with Dojo Query dojo. query('. spring-title. Pane-open > h 2'). for. Each(function(title. Element) Combining with Dojo Query dojo. query('. spring-title. Pane-open > h 2'). for. Each(function(title. Element) { Spring. add. Decoration(new Spring. Element. Decoration({ element. Id : title. Element. parent. Node. id, widget. Type : 'dijit. Title. Pane', widget. Attrs : { title : title. Element. inner. HTML, open : true }} )); }). style('display', 'none'); Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 38

Demo Progressive Enhancement with Spring Java. Script Copyright 2008 Spring. Source. Copying, publishing or Demo Progressive Enhancement with Spring Java. Script Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Summary • Simple yet powerful API • Write consistent Java. Script • Promote progressive Summary • Simple yet powerful API • Write consistent Java. Script • Promote progressive enhancement • Manage partial update complexities • Full-power of underlying toolkit available Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 40

Spring Web Flow Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web Flow Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web MVC Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 41

Spring Web Flow Overview • For implementing stateful flows – Reusable multi-step user dialogs Spring Web Flow Overview • For implementing stateful flows – Reusable multi-step user dialogs • Plugs into Spring MVC • Spring Web Flow 2 available now – Incorporates lessons learned from 1. 0 – Offers many new features Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 42

Web Flow Sweet Spot Copyright 2008 Spring. Source. Copying, publishing or distributing without express Web Flow Sweet Spot Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 43

New Web Flow 2 Features • Ajax support – Partial page re-rendering in flow New Web Flow 2 Features • Ajax support – Partial page re-rendering in flow DSL • Spring security integration • Flow-managed persistence • Convention-over-configuration – View rendering – Data binding and validation Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 44

Demo Essential Web Flow 2 features Copyright 2008 Spring. Source. Copying, publishing or distributing Demo Essential Web Flow 2 features Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Summary • Use Web Flow for stateful use cases – Wizards are a good Summary • Use Web Flow for stateful use cases – Wizards are a good example • Run flows alongside stateless Controllers • Web Flow 2 is a big step forward – Most sophisticated flow engine available Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 46

Spring Faces Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Spring Faces Spring Web Modules Spring Faces Spring Web Flow Spring Java. Script Spring Web MVC Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 47

Spring Faces • Makes JSF a view technology in Spring – Render JSF views Spring Faces • Makes JSF a view technology in Spring – Render JSF views from Spring MVC Controllers and Web Flows • Drives JSF lifecycle from within Spring environment Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 48

Spring Faces • All native Spring MVC features available • All phases of the Spring Faces • All native Spring MVC features available • All phases of the JSF lifecycle implemented – Stateless MVC views execute render lifecycle – Stateful web flows execute render and postback lifecycles Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 49

Key Benefits • Action-oriented (Spring MVC) – – – Flexible URL mapping REST-ful controller Key Benefits • Action-oriented (Spring MVC) – – – Flexible URL mapping REST-ful controller programming model Model binding and validation Request interception Exception handling Web Flow • Component-oriented (JSF) – Composite views (Facelets) – Ecosystem of available component libraries – Ability to create new components to enable reuse Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 50

Demo Spring Faces Combining the best of action-oriented and component-oriented development Copyright 2008 Spring. Demo Spring Faces Combining the best of action-oriented and component-oriented development Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Summary • Spring Faces enables the best of action-oriented and component-oriented development – Work Summary • Spring Faces enables the best of action-oriented and component-oriented development – Work with Spring MVC and JSF in the same application • Stateless Spring MVC Controllers can render transient JSF views • Stateful Spring Web Flows can render JSF views and process view post backs • Major JSF component libraries supported Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 52

Spring 3. 0 Roadmap • REST support – URI templates – Content negotiation – Spring 3. 0 Roadmap • REST support – URI templates – Content negotiation – JSON, Flex remoting • • Declarative Validation @Flow, as an alternative to XML Improved packaging Optimized for Java 5 and > Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited.

Presentation Summary • Spring offers a lot for rich web application development • Get Presentation Summary • Spring offers a lot for rich web application development • Get involved at www. springframework. org • Get enterprise support and tools at www. springsource. com • Join us for a rich web training workshop at www. springsource. com/training Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 54

Questions? 55 Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission Questions? 55 Copyright 2008 Spring. Source. Copying, publishing or distributing without express written permission is prohibited. 55