SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Spring Web Flow:
        A little flow of happiness.



Сергей Моренец
17 января 2013 г.
Agenda

•   Overview of the navigation history
•   Basics of SWF
•   Practical usage
•   Pros & Contras
•   Q&A
Spring MVC
Navigation overview
JSP
<jsp:forward page="/page.jsp" />

<%
response.sendRedirect(“page.jsp");
%>

<form action="search.jsp" name="search" method=“post">
<input type="text" name="search" value="by keyword">
<input type="submit" value="Go">
</form>
Spring MVC
Controller
@RequestMapping("/secure")
public class NavigationController {

     @RequestMapping("/operation")
     public String processOperationPage() {
         return “/corpus/operation";
     }
}

<a href="secure/operation.htm">Operation</a>
Struts
                     struts-config.xml
<action-mappings>
  <action path="/registration"
type="net.sf.struts.flow.FlowAction"
className="net.sf.struts.flow.FlowMapping">

     <forward name="name" path="/name.jsp"/>
     <forward name="hobbies" path="/hobbies.jsp"/>
     <forward name="summary" path="/summary.jsp"/>
  </action>
</action-mappings>
JSF
                      faces-config.xml

<navigation-rule>
  <from-view-id>page1.xhtml
  </from-view-id>
  <navigation-case>
     <from-outcome>page2</from-outcome>
     <to-view-id>/page2.xhtml</to-view-id>
  </navigation-case>
</navigation-rule>

<h:commandButton action="page2" value=“Next" />
Disadvantages
•   Visualizing the flow is very difficult
•   Mixed navigation and view
•   Overall navigation rules complexity
•   All-in-one navigation storage
•   Lack of state control/navigation customization
What is Spring Web Flow?
•   Developed by Erwin Vervaet in 2004
•   Initial version released in October, 2006
•   Spring MVC extension
•   Introduces flows concept
•   Extends application scopes
•   SWF 2.3.1 released in April, 2012
Erwin Vervaet
• Belgium citizen
• Holds master's degree in computer science
• Originator of Spring Web Flow Project
• Senior project manager together with Keith Donald
• Speaker on the most Java and Spring related
  themes
• Independent consultant www.ervacon.com
What is SWF for?
• How do you express page navigation rules?
• How do you manage navigation and conversational
  state?
• How do you facilitate modularization and reuse?
Use case
Request diagram
Flow definition
• XML document with predefined elements
• Flow definition is composed of a set of states
• Each state has one or more transitions that are used to
  move to another state
• A transition is triggered by an event
Sample flow
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/
webflow
http://www.springframework.org/schema/webflow/spring-
webflow-2.0.xsd">

[variables]

[input parameters]

[states]

</flow>
Flow
• A flow defines a conversion, or dialogue, between users
  and server that meets business goal
State
•   Action state
•   View state
•   Subflow state
•   Decision state
•   End state
Action state
<action-state id="moreAnswersNeeded">
  <evaluate expression="interview.moreAnswersNeeded()" />
  <transition on="yes" to="answerQuestions" />
  <transition on="no" to="finish" />
</action-state>


public boolean moreAnswersNeeded() {
  return currentAnswer < answers.size();
}
View state
<view-state id="answerQuestions" >
      <on-entry>
   <evaluate expression="interview.getNextQuestionSet()"
result="viewScope”
      </on-entry>
      <transition on="submitAnswers" to="moreAnswersNeeded">
 <evaluate expression="interview.recordAnswers(questionSet)" />
      </transition>
</view-state>
Decision state
<decision-state id="moreAnswersNeeded">
    <if test="interview.moreAnswersNeeded()"
then="answerQuestions" else="finish" />
</decision-state>

public boolean moreAnswersNeeded() {
  return currentAnswer < answers.size();
}
Subflow state
<subflow-state id=“registerUser" subflow=“register">
   <transition on=“userCreated" to=“finish">
      <evaluate expression=“interview.addUser(
currentEvent.attributes.user)“
</transition>
</subfow-state>
End state
<end-state id="finish" />
Start/end activity
<on-start>
  <evaluate expression=“mainService.startLock(currentUser)" />
</on-start>

<on-end>
<evaluate expression=“mainService.releaseLock(currentUser)" />
</on-end>
Transition binding
JSF
<h:form>
              <h:commandButton action="save"
value="#{msg['buttons.save']}" />
              <h:commandButton action="cancel"
value="#{msg['buttons.cancel']}"
                     immediate="true" />
</h:form>
Spring MVC
<form:form>
  <button type="submit" id=“save" name="_eventId_save">
     <spring:message code=“buttons.save"/>
  </button>
  <button type="submit" id="cancel" name="_eventId_cancel">
     <spring:message code="buttons.cancel"/>
  </button>
</form:form>
Post redirect get(PRG)
Variables scope
Spring
•   Singleton
•   Prototype
•   Request
•   Session
•   Global-session
SWF scope
•   Request
•   Flash
•   View
•   Flow
•   Conversation
Request scope
• Tied at the level of a single request
• Not linked to a flow execution by itself
Flash scope
• Extended request scope for PRG case
• Useful for rendering error/warning messages
View scope
• Can be referenced only within view state
• Useful for storing data required with given view only
Flow scope
• Lives within flow session
• Not available inside sub-flows
Conversation scope
• Lives within entire flow execution
• Available to all sub-flows
Flow scope usage
<var name="items" class="java.util.ArrayList" />

<action-state id="init">
  <on-entry>
    <evaluate
expression="mainService.lookupItems(items)" />
   </on-entry>
   <evaluate expression="items.size()"
result="flowScope.size" />
<transition on="success" to="viewitems" />
</action-state>
View scope usage
<view-state id="viewitems">
   <var name="items" class="java.util.ArrayList" />
   <on-entry>
     <evaluate
expression="mainService.lookupItems(items)" />
     <evaluate expression="items.size()“ result
="viewScope.size" />
   </on-entry>
</view-state>
Presentation level
<c:forEach items="#{items}“ var=“item">
      <h:outputText value="#{item.text}" />
</c:forEach>

<h:outputText value="#{size}" />
Flow tracking
Original link http://mysite/site/main?id=1

Target http://mysite.com/site/main?execution=e2s1
Flow tracking
public class PersistentUrlFlowHandler extends
DefaultFlowUrlHandler {
       public String createFlowExecutionUrl(String flowId,
                        String
flowExecutionKey, HttpServletRequest request) {
       String url =
super.createFlowExecutionUrl(flowId, flowExecutionKey, request);
       if (request.getParameter("id") != null) {
               StringBuilder builder = new StringBuilder(url);
               builder.append("&");

         appendQueryParameter(builder, "id", request.getParamet
er("id"));
                       return builder.toString();
               }
               return url;
         }
Flow tracking
Original link http://mysite/site/main?id=1

Target
http://mysite.com/site/main?execution=e2s1&id=1
Exception handling
• Transition on exception
• Custom exception handler
Transition on exception
<view-state id="authenticate" view="login" >
     <transition on="previous" to="previous"/>
     <transition on-exception="com.bookstore.
         AuthenticationException"
            to=“error_handler"/>
</view-state>

<action-state id=“error_handler”>
 ….
</action-state>
Exception handler
<exception-handler bean="exceptionHandlerBean" />

<bean id="exceptionHandlerBean"
  class="org.bookstore.exception. ExceptionHandlerBean">
  <property name="errorUrl" value="/error“ />
</bean>
Exception handler
public class WebflowExceptionHandlerBean implements
FlowExecutionExceptionHandler {
          private String errorUrl;

     public boolean canHandle(FlowExecutionException ex) {
            return findServiceException(ex) != null;
     }

     public void handle(FlowExecutionException ex, RequestControlContext context) {
            Exception flowException = findServiceException(ex);
            context.getExternalContext().requestExternalRedirect(errorUrl);
}

     private Exception findServiceException(FlowExecutionException ex) {
             Throwable cause = ex.getCause();
             if (cause instanceof AuthenticationException) {
                        return (Exception)cause;
             }
             return null;
}}
Flow inheritance
                           Parent-flow

<flow … abstract="true">
  <view-state id="someViewState" >
     <transition on="x" to="someState"/>
   </view-state>
</flow>

                              Child-flow
<flow parent="parent-flow">
   <view-state id="someViewState" >
      <transition on="y" to="someOtherState"/>
   </view-state>
</flow>
Integration
•   Spring MVC/Spring Security
•   JSF 2
•   Portlets
•   RichFaces/Apache MyFaces
•   Struts 2
Pros
• High-level navigation control with clear observable
  lifecycle
• Designed to be self contained
• Compile-independent
• Easy to understand and visualize
• Expression language support
• Custom validation (including AJAX)
• Integrates with major web frameworks
Cons
•   Requires Spring framework
•   Separate Spring project
•   Additional performance overhead
•   Lack of community support
•   Not suitable for simple or flow-free applications
Spring Tools Suite
• Eclipse development environment for building
  Spring-powered enterprise applications
• Visualization of Spring Web Flow
Flow graph
Flow editor
References
• Spring Web Flow 2 Web Development. Markus
  Stäuble, Sven Lüppken
• Pro Spring MVC: With Web Flow. Marten
  Deinum, Koen Serneels, Colin Yates, Seth
  Ladd, Christophe Vanfleteren
• Spring in Action.3rd edition .Craig Walls
Q&A




• Сергей Моренец, morenets@mail.ru

Weitere ähnliche Inhalte

Was ist angesagt?

Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITCarol McDonald
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RSFahad Golra
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVCGuy Nir
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web ServicesEmprovise
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component BehaviorsAndy Schwartz
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)Fahad Golra
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Peter R. Egli
 
Java web application development
Java web application developmentJava web application development
Java web application developmentRitikRathaur
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Arun Gupta
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsBG Java EE Course
 
Jax ws
Jax wsJax ws
Jax wsF K
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: ServletsFahad Golra
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2Jim Driscoll
 

Was ist angesagt? (20)

Interoperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSITInteroperable Web Services with JAX-WS and WSIT
Interoperable Web Services with JAX-WS and WSIT
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
Spring 3.x - Spring MVC
Spring 3.x - Spring MVCSpring 3.x - Spring MVC
Spring 3.x - Spring MVC
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web Services
 
JSF Component Behaviors
JSF Component BehaviorsJSF Component Behaviors
JSF Component Behaviors
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Java Server Faces
Java Server FacesJava Server Faces
Java Server Faces
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)
 
Jsf2.0 -4
Jsf2.0 -4Jsf2.0 -4
Jsf2.0 -4
 
Java web application development
Java web application developmentJava web application development
Java web application development
 
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
Spark IT 2011 - Simplified Web Development using Java Server Faces 2.0
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
Jax ws
Jax wsJax ws
Jax ws
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
Spring mvc
Spring mvcSpring mvc
Spring mvc
 
A Complete Tour of JSF 2
A Complete Tour of JSF 2A Complete Tour of JSF 2
A Complete Tour of JSF 2
 
Spring mvc 2.0
Spring mvc 2.0Spring mvc 2.0
Spring mvc 2.0
 

Andere mochten auch

JSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfacesJSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfacesStrannik_2013
 
Effective Java applications
Effective Java applicationsEffective Java applications
Effective Java applicationsStrannik_2013
 
Gradle.Enemy at the gates
Gradle.Enemy at the gatesGradle.Enemy at the gates
Gradle.Enemy at the gatesStrannik_2013
 
Getting ready to java 8
Getting ready to java 8Getting ready to java 8
Getting ready to java 8Strannik_2013
 
Effectiveness and code optimization in Java
Effectiveness and code optimization in JavaEffectiveness and code optimization in Java
Effectiveness and code optimization in JavaStrannik_2013
 
Java 8 in action.Jinq
Java 8 in action.JinqJava 8 in action.Jinq
Java 8 in action.JinqStrannik_2013
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesStrannik_2013
 
Gradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereGradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereStrannik_2013
 
Top 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleStrannik_2013
 
Git.From thorns to the stars
Git.From thorns to the starsGit.From thorns to the stars
Git.From thorns to the starsStrannik_2013
 
Spring Web flow. A little flow of happiness
Spring Web flow. A little flow of happinessSpring Web flow. A little flow of happiness
Spring Web flow. A little flow of happinessStrannik_2013
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your developmentStrannik_2013
 
Serialization and performance in Java
Serialization and performance in JavaSerialization and performance in Java
Serialization and performance in JavaStrannik_2013
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Strannik_2013
 
Happiness is a State of Mind
Happiness is a State of MindHappiness is a State of Mind
Happiness is a State of MindRolley Hurley
 
The Artof Purim2010
The Artof Purim2010The Artof Purim2010
The Artof Purim2010Myrna Teck
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your developmentStrannik_2013
 

Andere mochten auch (20)

JSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfacesJSF 2: Myth of panacea? Magic world of user interfaces
JSF 2: Myth of panacea? Magic world of user interfaces
 
Effective Java applications
Effective Java applicationsEffective Java applications
Effective Java applications
 
Gradle.Enemy at the gates
Gradle.Enemy at the gatesGradle.Enemy at the gates
Gradle.Enemy at the gates
 
Getting ready to java 8
Getting ready to java 8Getting ready to java 8
Getting ready to java 8
 
Effectiveness and code optimization in Java
Effectiveness and code optimization in JavaEffectiveness and code optimization in Java
Effectiveness and code optimization in Java
 
Java 8 in action.Jinq
Java 8 in action.JinqJava 8 in action.Jinq
Java 8 in action.Jinq
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypes
 
Gradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhereGradle 2.Write once, builde everywhere
Gradle 2.Write once, builde everywhere
 
Top 10 reasons to migrate to Gradle
Top 10 reasons to migrate to GradleTop 10 reasons to migrate to Gradle
Top 10 reasons to migrate to Gradle
 
Git.From thorns to the stars
Git.From thorns to the starsGit.From thorns to the stars
Git.From thorns to the stars
 
Spring Web flow. A little flow of happiness
Spring Web flow. A little flow of happinessSpring Web flow. A little flow of happiness
Spring Web flow. A little flow of happiness
 
Spring Boot. Boot up your development
Spring Boot. Boot up your developmentSpring Boot. Boot up your development
Spring Boot. Boot up your development
 
Serialization and performance in Java
Serialization and performance in JavaSerialization and performance in Java
Serialization and performance in Java
 
Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015Spring Boot. Boot up your development. JEEConf 2015
Spring Boot. Boot up your development. JEEConf 2015
 
Happiness is a State of Mind
Happiness is a State of MindHappiness is a State of Mind
Happiness is a State of Mind
 
Purim
PurimPurim
Purim
 
Happiness
HappinessHappiness
Happiness
 
The Artof Purim2010
The Artof Purim2010The Artof Purim2010
The Artof Purim2010
 
19 purim
19 purim19 purim
19 purim
 
Spring.Boot up your development
Spring.Boot up your developmentSpring.Boot up your development
Spring.Boot up your development
 

Ähnlich wie Spring Web Flow. A little flow of happiness.

Web flowpresentation
Web flowpresentationWeb flowpresentation
Web flowpresentationRoman Brovko
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortalJennifer Bourey
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen LjuSkills Matter
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen LjuSkills Matter
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJini Lee
 
BPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsBPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsAlfresco Software
 
BPM-2 Introduction to Advanced Workflows
BPM-2 Introduction to Advanced WorkflowsBPM-2 Introduction to Advanced Workflows
BPM-2 Introduction to Advanced WorkflowsAlfresco Software
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces Skills Matter
 
Lifecycle Management of SOA Artifacts for WSO2 Products
Lifecycle Management of SOA Artifacts for WSO2 ProductsLifecycle Management of SOA Artifacts for WSO2 Products
Lifecycle Management of SOA Artifacts for WSO2 ProductsWSO2
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web FlowDzmitry Naskou
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and ModernizrJussi Pohjolainen
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauSpiffy
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieOPEN KNOWLEDGE GmbH
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Arun Gupta
 
Spring Web Flow Grail's Plugin
Spring Web Flow Grail's PluginSpring Web Flow Grail's Plugin
Spring Web Flow Grail's PluginC-DAC
 

Ähnlich wie Spring Web Flow. A little flow of happiness. (20)

Web flowpresentation
Web flowpresentationWeb flowpresentation
Web flowpresentation
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
Primefaces Nextgen Lju
Primefaces Nextgen LjuPrimefaces Nextgen Lju
Primefaces Nextgen Lju
 
GR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails WebflowGR8Conf 2011: Grails Webflow
GR8Conf 2011: Grails Webflow
 
Javatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparisonJavatwo2012 java frameworkcomparison
Javatwo2012 java frameworkcomparison
 
BPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced WorkflowsBPM-1 Introduction to Advanced Workflows
BPM-1 Introduction to Advanced Workflows
 
BPM-2 Introduction to Advanced Workflows
BPM-2 Introduction to Advanced WorkflowsBPM-2 Introduction to Advanced Workflows
BPM-2 Introduction to Advanced Workflows
 
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
In The Brain of Cagatay Civici: Exploring JavaServer Faces 2.0 and PrimeFaces
 
Lifecycle Management of SOA Artifacts for WSO2 Products
Lifecycle Management of SOA Artifacts for WSO2 ProductsLifecycle Management of SOA Artifacts for WSO2 Products
Lifecycle Management of SOA Artifacts for WSO2 Products
 
Spring Framework - Web Flow
Spring Framework - Web FlowSpring Framework - Web Flow
Spring Framework - Web Flow
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
Jsf presentation
Jsf presentationJsf presentation
Jsf presentation
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)Unit 07: Design Patterns and Frameworks (3/3)
Unit 07: Design Patterns and Frameworks (3/3)
 
Struts Overview
Struts OverviewStruts Overview
Struts Overview
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative WebtechnologieMVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
 
Spring Web Flow
Spring Web FlowSpring Web Flow
Spring Web Flow
 
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
Hyperproductive JSF 2.0 @ JavaOne Brazil 2010
 
Spring Web Flow Grail's Plugin
Spring Web Flow Grail's PluginSpring Web Flow Grail's Plugin
Spring Web Flow Grail's Plugin
 

Mehr von Alex Tumanoff

Sql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen NedaskivskyiSql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen NedaskivskyiAlex Tumanoff
 
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis ReznikOdessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis ReznikAlex Tumanoff
 
Azure data bricks by Eugene Polonichko
Azure data bricks by Eugene PolonichkoAzure data bricks by Eugene Polonichko
Azure data bricks by Eugene PolonichkoAlex Tumanoff
 
Sdlc by Anatoliy Anthony Cox
Sdlc by  Anatoliy Anthony CoxSdlc by  Anatoliy Anthony Cox
Sdlc by Anatoliy Anthony CoxAlex Tumanoff
 
Kostenko ux november-2014_1
Kostenko ux november-2014_1Kostenko ux november-2014_1
Kostenko ux november-2014_1Alex Tumanoff
 
Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3Alex Tumanoff
 
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас..."Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...Alex Tumanoff
 
Sql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton VidishchevSql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton VidishchevAlex Tumanoff
 
Navigation map factory by Alexey Klimenko
Navigation map factory by Alexey KlimenkoNavigation map factory by Alexey Klimenko
Navigation map factory by Alexey KlimenkoAlex Tumanoff
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsAlex Tumanoff
 
Игры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей РыбаковИгры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей РыбаковAlex Tumanoff
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapterAlex Tumanoff
 
Async clinic by by Sergey Teplyakov
Async clinic by by Sergey TeplyakovAsync clinic by by Sergey Teplyakov
Async clinic by by Sergey TeplyakovAlex Tumanoff
 
Deep Dive C# by Sergey Teplyakov
Deep Dive  C# by Sergey TeplyakovDeep Dive  C# by Sergey Teplyakov
Deep Dive C# by Sergey TeplyakovAlex Tumanoff
 
Bdd by Dmitri Aizenberg
Bdd by Dmitri AizenbergBdd by Dmitri Aizenberg
Bdd by Dmitri AizenbergAlex Tumanoff
 
Неформальные размышления о сертификации в IT
Неформальные размышления о сертификации в ITНеформальные размышления о сертификации в IT
Неформальные размышления о сертификации в ITAlex Tumanoff
 
Разработка расширений Firefox
Разработка расширений FirefoxРазработка расширений Firefox
Разработка расширений FirefoxAlex Tumanoff
 
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So..."AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...Alex Tumanoff
 
Patterns of parallel programming
Patterns of parallel programmingPatterns of parallel programming
Patterns of parallel programmingAlex Tumanoff
 

Mehr von Alex Tumanoff (20)

Sql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen NedaskivskyiSql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen Nedaskivskyi
 
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis ReznikOdessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
 
Azure data bricks by Eugene Polonichko
Azure data bricks by Eugene PolonichkoAzure data bricks by Eugene Polonichko
Azure data bricks by Eugene Polonichko
 
Sdlc by Anatoliy Anthony Cox
Sdlc by  Anatoliy Anthony CoxSdlc by  Anatoliy Anthony Cox
Sdlc by Anatoliy Anthony Cox
 
Kostenko ux november-2014_1
Kostenko ux november-2014_1Kostenko ux november-2014_1
Kostenko ux november-2014_1
 
Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3
 
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас..."Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
 
Spring.new hope.1.3
Spring.new hope.1.3Spring.new hope.1.3
Spring.new hope.1.3
 
Sql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton VidishchevSql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton Vidishchev
 
Navigation map factory by Alexey Klimenko
Navigation map factory by Alexey KlimenkoNavigation map factory by Alexey Klimenko
Navigation map factory by Alexey Klimenko
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey Morenets
 
Игры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей РыбаковИгры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей Рыбаков
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapter
 
Async clinic by by Sergey Teplyakov
Async clinic by by Sergey TeplyakovAsync clinic by by Sergey Teplyakov
Async clinic by by Sergey Teplyakov
 
Deep Dive C# by Sergey Teplyakov
Deep Dive  C# by Sergey TeplyakovDeep Dive  C# by Sergey Teplyakov
Deep Dive C# by Sergey Teplyakov
 
Bdd by Dmitri Aizenberg
Bdd by Dmitri AizenbergBdd by Dmitri Aizenberg
Bdd by Dmitri Aizenberg
 
Неформальные размышления о сертификации в IT
Неформальные размышления о сертификации в ITНеформальные размышления о сертификации в IT
Неформальные размышления о сертификации в IT
 
Разработка расширений Firefox
Разработка расширений FirefoxРазработка расширений Firefox
Разработка расширений Firefox
 
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So..."AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
 
Patterns of parallel programming
Patterns of parallel programmingPatterns of parallel programming
Patterns of parallel programming
 

Spring Web Flow. A little flow of happiness.

  • 1. Spring Web Flow: A little flow of happiness. Сергей Моренец 17 января 2013 г.
  • 2. Agenda • Overview of the navigation history • Basics of SWF • Practical usage • Pros & Contras • Q&A
  • 3.
  • 6. JSP <jsp:forward page="/page.jsp" /> <% response.sendRedirect(“page.jsp"); %> <form action="search.jsp" name="search" method=“post"> <input type="text" name="search" value="by keyword"> <input type="submit" value="Go"> </form>
  • 7. Spring MVC Controller @RequestMapping("/secure") public class NavigationController { @RequestMapping("/operation") public String processOperationPage() { return “/corpus/operation"; } } <a href="secure/operation.htm">Operation</a>
  • 8. Struts struts-config.xml <action-mappings> <action path="/registration" type="net.sf.struts.flow.FlowAction" className="net.sf.struts.flow.FlowMapping"> <forward name="name" path="/name.jsp"/> <forward name="hobbies" path="/hobbies.jsp"/> <forward name="summary" path="/summary.jsp"/> </action> </action-mappings>
  • 9. JSF faces-config.xml <navigation-rule> <from-view-id>page1.xhtml </from-view-id> <navigation-case> <from-outcome>page2</from-outcome> <to-view-id>/page2.xhtml</to-view-id> </navigation-case> </navigation-rule> <h:commandButton action="page2" value=“Next" />
  • 10. Disadvantages • Visualizing the flow is very difficult • Mixed navigation and view • Overall navigation rules complexity • All-in-one navigation storage • Lack of state control/navigation customization
  • 11. What is Spring Web Flow? • Developed by Erwin Vervaet in 2004 • Initial version released in October, 2006 • Spring MVC extension • Introduces flows concept • Extends application scopes • SWF 2.3.1 released in April, 2012
  • 12. Erwin Vervaet • Belgium citizen • Holds master's degree in computer science • Originator of Spring Web Flow Project • Senior project manager together with Keith Donald • Speaker on the most Java and Spring related themes • Independent consultant www.ervacon.com
  • 13. What is SWF for? • How do you express page navigation rules? • How do you manage navigation and conversational state? • How do you facilitate modularization and reuse?
  • 16. Flow definition • XML document with predefined elements • Flow definition is composed of a set of states • Each state has one or more transitions that are used to move to another state • A transition is triggered by an event
  • 18. Flow • A flow defines a conversion, or dialogue, between users and server that meets business goal
  • 19. State • Action state • View state • Subflow state • Decision state • End state
  • 20. Action state <action-state id="moreAnswersNeeded"> <evaluate expression="interview.moreAnswersNeeded()" /> <transition on="yes" to="answerQuestions" /> <transition on="no" to="finish" /> </action-state> public boolean moreAnswersNeeded() { return currentAnswer < answers.size(); }
  • 21. View state <view-state id="answerQuestions" > <on-entry> <evaluate expression="interview.getNextQuestionSet()" result="viewScope” </on-entry> <transition on="submitAnswers" to="moreAnswersNeeded"> <evaluate expression="interview.recordAnswers(questionSet)" /> </transition> </view-state>
  • 22. Decision state <decision-state id="moreAnswersNeeded"> <if test="interview.moreAnswersNeeded()" then="answerQuestions" else="finish" /> </decision-state> public boolean moreAnswersNeeded() { return currentAnswer < answers.size(); }
  • 23. Subflow state <subflow-state id=“registerUser" subflow=“register"> <transition on=“userCreated" to=“finish"> <evaluate expression=“interview.addUser( currentEvent.attributes.user)“ </transition> </subfow-state>
  • 25. Start/end activity <on-start> <evaluate expression=“mainService.startLock(currentUser)" /> </on-start> <on-end> <evaluate expression=“mainService.releaseLock(currentUser)" /> </on-end>
  • 27. JSF <h:form> <h:commandButton action="save" value="#{msg['buttons.save']}" /> <h:commandButton action="cancel" value="#{msg['buttons.cancel']}" immediate="true" /> </h:form>
  • 28. Spring MVC <form:form> <button type="submit" id=“save" name="_eventId_save"> <spring:message code=“buttons.save"/> </button> <button type="submit" id="cancel" name="_eventId_cancel"> <spring:message code="buttons.cancel"/> </button> </form:form>
  • 31. Spring • Singleton • Prototype • Request • Session • Global-session
  • 32. SWF scope • Request • Flash • View • Flow • Conversation
  • 33. Request scope • Tied at the level of a single request • Not linked to a flow execution by itself
  • 34. Flash scope • Extended request scope for PRG case • Useful for rendering error/warning messages
  • 35. View scope • Can be referenced only within view state • Useful for storing data required with given view only
  • 36. Flow scope • Lives within flow session • Not available inside sub-flows
  • 37. Conversation scope • Lives within entire flow execution • Available to all sub-flows
  • 38. Flow scope usage <var name="items" class="java.util.ArrayList" /> <action-state id="init"> <on-entry> <evaluate expression="mainService.lookupItems(items)" /> </on-entry> <evaluate expression="items.size()" result="flowScope.size" /> <transition on="success" to="viewitems" /> </action-state>
  • 39. View scope usage <view-state id="viewitems"> <var name="items" class="java.util.ArrayList" /> <on-entry> <evaluate expression="mainService.lookupItems(items)" /> <evaluate expression="items.size()“ result ="viewScope.size" /> </on-entry> </view-state>
  • 40. Presentation level <c:forEach items="#{items}“ var=“item"> <h:outputText value="#{item.text}" /> </c:forEach> <h:outputText value="#{size}" />
  • 41. Flow tracking Original link http://mysite/site/main?id=1 Target http://mysite.com/site/main?execution=e2s1
  • 42. Flow tracking public class PersistentUrlFlowHandler extends DefaultFlowUrlHandler { public String createFlowExecutionUrl(String flowId, String flowExecutionKey, HttpServletRequest request) { String url = super.createFlowExecutionUrl(flowId, flowExecutionKey, request); if (request.getParameter("id") != null) { StringBuilder builder = new StringBuilder(url); builder.append("&"); appendQueryParameter(builder, "id", request.getParamet er("id")); return builder.toString(); } return url; }
  • 43. Flow tracking Original link http://mysite/site/main?id=1 Target http://mysite.com/site/main?execution=e2s1&id=1
  • 44. Exception handling • Transition on exception • Custom exception handler
  • 45. Transition on exception <view-state id="authenticate" view="login" > <transition on="previous" to="previous"/> <transition on-exception="com.bookstore. AuthenticationException" to=“error_handler"/> </view-state> <action-state id=“error_handler”> …. </action-state>
  • 46. Exception handler <exception-handler bean="exceptionHandlerBean" /> <bean id="exceptionHandlerBean" class="org.bookstore.exception. ExceptionHandlerBean"> <property name="errorUrl" value="/error“ /> </bean>
  • 47. Exception handler public class WebflowExceptionHandlerBean implements FlowExecutionExceptionHandler { private String errorUrl; public boolean canHandle(FlowExecutionException ex) { return findServiceException(ex) != null; } public void handle(FlowExecutionException ex, RequestControlContext context) { Exception flowException = findServiceException(ex); context.getExternalContext().requestExternalRedirect(errorUrl); } private Exception findServiceException(FlowExecutionException ex) { Throwable cause = ex.getCause(); if (cause instanceof AuthenticationException) { return (Exception)cause; } return null; }}
  • 48. Flow inheritance Parent-flow <flow … abstract="true"> <view-state id="someViewState" > <transition on="x" to="someState"/> </view-state> </flow> Child-flow <flow parent="parent-flow"> <view-state id="someViewState" > <transition on="y" to="someOtherState"/> </view-state> </flow>
  • 49. Integration • Spring MVC/Spring Security • JSF 2 • Portlets • RichFaces/Apache MyFaces • Struts 2
  • 50. Pros • High-level navigation control with clear observable lifecycle • Designed to be self contained • Compile-independent • Easy to understand and visualize • Expression language support • Custom validation (including AJAX) • Integrates with major web frameworks
  • 51. Cons • Requires Spring framework • Separate Spring project • Additional performance overhead • Lack of community support • Not suitable for simple or flow-free applications
  • 52. Spring Tools Suite • Eclipse development environment for building Spring-powered enterprise applications • Visualization of Spring Web Flow
  • 55. References • Spring Web Flow 2 Web Development. Markus Stäuble, Sven Lüppken • Pro Spring MVC: With Web Flow. Marten Deinum, Koen Serneels, Colin Yates, Seth Ladd, Christophe Vanfleteren • Spring in Action.3rd edition .Craig Walls