41
Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. What’s new in Spring Web Flow 2.0 Agim Emruli SpringSource Germany

Spring Web Flow 2.0 - jugs.org · •Spring Web Flow 2.0 supports both integration styles •New integration style opens new possibilities –Management of view specific state inside

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

What’s new in Spring Web Flow2.0

Agim Emruli

SpringSource Germany

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 2

About me

• Senior Consultant

• Spring / Spring Web Flow Training andConsulting

[email protected]

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 3

Agenda

• Web Flow overview

• Web Flow 2.0 features

• Spring Faces

• What‘s coming

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 4

Agenda

• Web Flow overview

• Web Flow 2.0 features

• Spring Faces

• What‘s coming

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 5

Web Flow Overview

• Web application Framework– Provides a flow abstraction for page flows

• States

• Transitions

• Events

– Fills the gap between stateless http andconversational (web) applications

– Integration into modern web frameworks

• JSF, Spring MVC, Struts 1.x

• DOJO, ExtJS

• Part of the Spring portfolio

• Production ready since 2006

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 6

Web Flow 2.0 Features

• Web framework integration

• Flow managed persistence context

• Message abstraction

• Security

• Other improvements

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 7

Web Framework IntegrationIn SWF 1.0

• Spring Web Flow 1.0 provides out-of-the-box integrations for– Spring MVC

– Java Server Faces

– Struts 1.x

• Integration through framework specificcontrollers– Web Flow handles the action phase

– Web framework handles the render phase

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 8

Web Framework IntegrationIn SWF 1.0

Front ControllerController 1

Controller 2

Controller n

Spring Web Flow

ControllerView

request

response

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 9

Web Framework IntegrationIn SWF 1.0

• Advantages– Easy adoption

– „smooth“ migration path

• Web Flow can be easily added into an existingapplication

– Mix and match

• SWF for complex flows

• Controllers for standard navigation

• Disadvantages– No control of the rendering process in Web Flow

• No Flow Managed Resources for view rendering

– Front controller specific error handling

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 10

Web Framework IntegrationIn SWF 2.0

• Spring Web Flow handles the action andview rendering phase

– One controller engine with full control overthe lifecycle

– Unified front controller servlet

• Integration through Spring’sDispatcherServlet

– One configuration across all web frameworks

– The view technology is interchangeable

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 11

Web Framework IntegrationIn SWF 2.0

Spring

DispatcherServlet

Controller 1

Controller 2

Controller n

Spring Web Flow

ControllerView

request

response

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 12

Web Framework IntegrationIn SWF 2.0

• Advantages– Unified listener model

• Persistent context management

• Error handling

• Security

– No ugly servlet filters

– Interchangeable view-technologies

• Mix JSF views with Spring MVC views

– Unified SWF configuration across web frameworks

• Disadvantages– More changes in the existing Front Controller setup

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 13

Integration Summary

• Spring Web Flow 2.0 supports bothintegration styles

• New integration style opens newpossibilities

– Management of view specific state inside theWeb Flow system

• JSF component state

• Unified front controller interface acrossweb frameworks

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 14

Flow Managed PersistenceServices

• O/R Mappers need a persistence context– Represents the unit-of-work

– Caches domain objects

– Dirty detection for changed objects

• Persistence Context is typically transactionscoped– Not available for view-rendering

• LazyLoadingExceptions

– Every transaction creates a new context

• Objects must be manually reattached to the newcontext

– NonUnqiueObjectExceptions

• No cache reuse across transactions

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 15

Transaction ScopedPersistence Context

Flow

Event

Transaction

Persistence context

Event

Transaction

Persistence context

P D P

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 16

Flow Managed PersistenceContext

• Persistence context is controlled through theFlow lifecycle– One persistence context per Flow

– „Dirty Objects“ are active through the Flow lifecycleuntil the end

• Changed will be flushed/discarded at the end of the flow

– Persistence context is available while rendering theview

– Persistence context is restorable throughcontinuations

– Almost atomic conversations

• Depends on key generation strategy

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 17

Flow Managed PersistenceContext

Flow

Event

Transaction

Event

Transaction

Persistence context

P P

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 18

Flow Managed PersistenceContext

• Persistence Context is activated on a per-flow-basis<flow>

<peristence-context>

</flow>

• Commit and rollback behaviour is end-statedriven<end-state id=„processBooking“>

<attribute name="commit" value="true"type="boolean" />

</end-stade>

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 19

Flow Managed PersistenceContext Summary

• Web Flow supports multiple O/RMappers– Hibernate

– JPA (OpenJPA, Toplink Essentials)

• Caveats are– Concurrent modification

– Time to flush

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 20

Message Abstraction

• Unified message abstraction, acrossdifferent web frameworks

• Also available after a redirect

• Fluent interface

context.getMessageContext().addMessage(

new MessageBuilder().

source("checkinDate").

defaultText("some default message")

.error().build())

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 21

Flow Security

• Spring Security protects differentresources– URL resources

– Method calls

• Web Flow 2.0 uses Spring Security toenforce security constraints in the flow– Flow

– States

– Transitions

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 22

Other Improvements

• Improved Back handling

• Spring Web Flow scopes for theBeanFactory

– Conversation, flow

• Flow inheritance

• Convenience shortcuts inside the flowdefinition

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 23

Agenda

• Web Flow overview

• Web Flow 2.0 features

• Spring Faces

• What‘s coming

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 24

What is Spring Faces?

• Spring’s JSF integration library– JSF 1.1 or JSF 1.2

• Spring Faces is currently shipped asmodule of the Spring Web Flow 2.0distribution– Runs on Java 1.4 or >

• Provides complete support fordeveloping component-based webapplications with JSF

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 25

Spring Faces Architecture

• Builds on Spring Web Flow in three ways

– For view event handling / navigation

– For application state management

– For modularization of your JSF application

• Provides a “progressive” JSF component library

– Degrades when javascript is not available on client

– Built on a new “Spring UI” Javascript abstraction framework• Integrates Dojo 1.0

• Provides Ajax support in a JSF environment

• Integrates with the Facelets templating engine and allpopular JSF component libraries

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 26

Spring Faces Architecture

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 27

Spring Faces Features

• Zero faces-config configuration

– All features are enabled for you simply by putting spring-faces.jar in your classpath

• All the power of Web Flow

– Define rich, modular definitions of application flow

– Get conversational and intra-page state management

– Map UI events directly to backing Spring beans

– Built in support for the POST+REDIRECT+GET pattern

• Progressive command-button, command-link, andvalidation components

• Ajax enabled components

– Signal intra-page events that invoke actions and re-renderfragments of the current page

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 28

Spring Faces SampleApplication Walkthrough

• Consider the “Hotel Booking” sampleapplication

• Partitioned into two modules

– A “main” module that lets you performsearches, view results, and select a resultfor booking

– A “booking” module that helps you book ahotel

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 29

Modular Approach

• Each module encapsulates all of itsdependent UI artifacts

– The module’s flow definition

• Defines control flow and UI event handling logic

– JSF view templates

– Resources such as message bundles

• Modules can invoke each other

– “main” may call “booking” during the courseof its execution

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 30

Hotel Booking Modules

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 31

Module Flow Definition

• Module control logic is implementedusing a Web Flow definition

• For example, the “main” flow definitiondefines the rules to

– Render the main search page on startup

– Respond to JSF action events on postback tocontinue processing

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 32

Main Web Flow DefinitionExample

<flow>

<view-state id=”mainSearchPage" view="main.xhtml">

<transition on="findHotels" to=”resultsPage" />

<transition on="cancelBooking" to="cancelBooking" />

</view-state>

<view-state id=”resultsPage" view=”results.xhtml">

<render-actions>

<action method="findHotels" bean="mainActions" />

</render-actions>

<transition on="selectHotel" to=”detailsPage”/>

<transition on="changeSearch" to=”mainSearchPage"/>

</view-state> …

<flow>

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 33

JSF View Templates

• Rendered JSF templates are juststandard JSF views

• Integrating other JSF componentlibraries is straightforward

• You may also use the Spring Facescomponent library to progressivelyenhance the page with Javascriptbehavior– If Javascript is available on the client

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 34

Spring Faces ProgressiveComponents

• <sf:commandButton>– Is Javascript available? If yes, fire a Ajax

action event when the button is clicked; onlyre-render components effected by the eventin the response• If no, submit the form as normal, causing a full

page refresh

• <sf:commandLink>– Is Javascript available? If yes, render as a

link that submits a form• If no, render link as a plain button

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

Spring Faces ProgressiveValidation

• <sf:clientTextValidator> - decorate a text field withstring validation

• <sf:numberTextValidator> - decorate a text field withnumber validation

• <sf:dateTextValidator> - decorate a text field with adate chooser

• <sf:currencyTextValidator> - decorate a text field withmoney validation

• <sf:validateAllOnClick> - force validation of all fieldswhen a command button is clicked

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 36

Agenda

• General Topics

• Spring Faces

• What‘s Coming

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

What’s Coming

• Spring Web Flow 2.0

– Milestone 4 this week

– 2.0 Final in Q2/2008

• Spring Web 3.0

– A new, declarative “site definition language”

– Powerful new ways of defining site controllogic, including a Groovy-based DSL

– Further JSF integration convenience

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 38

Site Definition LanguageExample

<site id="hotels">

<page id="search">

<var name="criteria" class="ebookings.hotels.SearchCriteria" />

<transition event="search" target="results"/>

<input name="criteria" />

</transition>

</page>

<page id="results">

<on-entry><eval exp="${criteria.executeSearch()}" /></on-entry>

<transition event="select" to="book">

<input name="hotelId" value="${eventParams.selection.id}"

</transition>

</page>

<flow id="book">

<transition event="bookingAuthorized" target="search" />

</flow>

</site>

Each page is bookmarkable at a resource URI

Transition input is sent through the page redirect for you!

Starts a controlled navigation (no bookmarking the steps of it)

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited. 39

Summary

• Spring Web Flow 2.0 introduces a newuniversal controller engine

• Support for extended persistencecontext

• Spring Security integration

• Powerful JSF integration

• ... Backward compatible to Web Flow1.0

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Q & A

Copyright 2008 SpringSource. Copying, publishing or distributing without express written permission is prohibited.

Thanks!

Agim Emruli

[email protected]