Spring Framework - Web Flow

8,131 views
8,003 views

Published on

Introduction to Spring Web Flow.

Published in: Technology, Business
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
8,131
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
301
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

Spring Framework - Web Flow

  1. 1. Spring Framework - Web Flow SPRING FRAMEWORKDmitry Noskov Spring Web Flow 2.3
  2. 2. The Spring WEB stack Spring Framework - Web Flow Dmitry Noskov
  3. 3. Introduction MVC extension focused on the definition and execution of page flow Integration  Spring MVC  JSF  Portlet Spring Framework - Web Flow Dmitry Noskov
  4. 4. What is flow? Spring Framework - Web Flow Dmitry Noskov
  5. 5. Typical web application Spring Framework - Web Flow Dmitry Noskov
  6. 6. Process driven application Spring Framework - Web Flow Dmitry Noskov
  7. 7. Configuration Spring Framework - Web Flow Dmitry Noskov
  8. 8. Web Flow schema<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/ webflow-confighttp://www.springframework.org/schema/webflow-config /spring-webflow-config-2.3.xsd"> Spring Framework - Web Flow Dmitry Noskov
  9. 9. Flow builder basic<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true" validator="validator" conversion-service="customConversionService" expression-parser="ognl"/> Spring Framework - Web Flow Dmitry Noskov
  10. 10. Flow registry basic<webflow:flow-registry id="flowRegistry" flow-builder-services="builderServices" base-path="/WEB-INF" parent="parent"> <!—flow locations--></webflow:flow-registry> specify path<webflow:flow-location id="" path="/hotels/booking/booking-flow.xml"/> location pattern<webflow:flow-location-pattern value="/**/*-flow.xml" /> Spring Framework - Web Flow Dmitry Noskov
  11. 11. Flow executor basic<webflow:flow-executor id="flowExecutor" flow-registry="ref"> <!—listeners, repositories--></webflow:flow-executor> listener<webflow:flow-execution-listeners> <webflow:listener ref="listener" criteria="*"/></webflow:flow-execution-listeners> repository<webflow:flow-execution-repository max-executions="5" max-execution-snapshots="10"/> Spring Framework - Web Flow Dmitry Noskov
  12. 12. Workflow image Spring Framework - Web Flow Dmitry Noskov
  13. 13. Dispatcher servlet<servlet><servlet-name>Spring MVC Dispatcher Servlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param> <param-name>contextConfigLocation</param-name> <param-value></param-value></init-param></servlet><servlet-mapping><servlet-name>Spring MVC Dispatcher Servlet</servlet-name><url-pattern>/</url-pattern></servlet-mapping> Spring Framework - Web Flow Dmitry Noskov
  14. 14. Dispatching FlowHandlerMapping<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> <property name="order" value="-1"/> <property name="flowRegistry" ref="flowRegistry" /></bean> FlowHandlerAdapter<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property name="flowExecutor" ref="flowExecutor"/></bean> Spring Framework - Web Flow Dmitry Noskov
  15. 15. Flow Spring Framework - Web Flow Dmitry Noskov
  16. 16. Flow schema<?xml version="1.0" encoding="UTF-8"?><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"> …states…</flow> Spring Framework - Web Flow Dmitry Noskov
  17. 17. Essential elements state transition flow data expression language Spring Framework - Web Flow Dmitry Noskov
  18. 18. Input attribute simple <input name="hotelId" required="true" /> assign input value <input name="hotelId" value="flowScope.bean.itemId" /> Spring Framework - Web Flow Dmitry Noskov
  19. 19. Output value flow attribute<end-state id="bookingConfirmed"> <output name="booking"/></end-state> specific<end-state id="bookingConfirmed"> <output name="booking" value="booking.id"/></end-state> Spring Framework - Web Flow Dmitry Noskov
  20. 20. Data scopeConversationFlowRequestFlashView Spring Framework - Web Flow Dmitry Noskov
  21. 21. States view action decision subflow end Spring Framework - Web Flow Dmitry Noskov
  22. 22. Expression language expression types  standard  template implementation  Spring EL  Unified EL  OGNL Spring Framework - Web Flow Dmitry Noskov
  23. 23. Special variables flowScope, viewScope, etc. requestParameters currentEvent currentUser messageContext, resourceBoundle flowRequestContext, flowExecutionContext flowExecutionUrl externalContext Spring Framework - Web Flow Dmitry Noskov
  24. 24. Typical flow Spring Framework - Web Flow Dmitry Noskov
  25. 25. Rendering views Spring Framework - Web Flow Dmitry Noskov
  26. 26. Simple view view state<view-state id="enterBookingDetails" model="booking" view="path"> <transition on="proceed" to="reviewBooking" /> <transition on="cancel" to="cancel" /></view-state> view detection  by state id  by relative view id  by absolute view id Spring Framework - Web Flow Dmitry Noskov
  27. 27. View resolution default mvc view resolver<webflow:flow-builder-services view-factory-creator="mvc" /><bean id="mvc" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> <property name="viewResolvers" ref="tilesViewResolver"/> <property name="useSpringBeanBinding" value="true" /></bean> Spring Framework - Web Flow Dmitry Noskov
  28. 28. Firing events simple link<a href="${flowExecutionUrl}&_eventId=cancel/">Cancel</a> hidden field<input type="submit" value="Cancel" /><input type="hidden" name="_eventId" value="cancel" /> submit button<button type="submit" name="_eventId_proceed">Proceed</button><button type="submit" name="_eventId_cancel">Cancel</button> Spring Framework - Web Flow Dmitry Noskov
  29. 29. Advanced view<view-state id="enterBookingDetails" view="" model="booking" parent="" popup="true/false" redirect="true/false" > <var name="" class=""/> <binder> <binding property="checkinDate" /> </binder></view-state> Spring Framework - Web Flow Dmitry Noskov
  30. 30. Model binding<on-start> <evaluate expression="bookingService.createBooking(hotelId)" result="flowScope.booking" /></on-start><view-state id="enterBookingDetails" model="booking"> <binder> <binding property="checkinDate" /> <binding property="checkoutDate" /> <binding property="creditCard" /> </binder> <transition on="proceed" to="reviewBooking" /> <transition on="cancel" to="cancel" bind="false" /></view-state> Spring Framework - Web Flow Dmitry Noskov
  31. 31. Validation JSR-303<webflow:flow-builder-services id="" validator="validator" /><bean id="validator" class="…LocalValidatorFactoryBean"/> model validate methodpublic class Booking implements Serializable { public void validateEnterBookingDetails(ValidationContext c) {}} separate validatorpublic class BookingValidator { public void validate(Booking b, ValidationContext c) {} public void validateEnterBookingDetails(…) {}} Spring Framework - Web Flow Dmitry Noskov
  32. 32. Execution actions Spring Framework - Web Flow Dmitry Noskov
  33. 33. Actions set variable <set name="flowScope.key" value="value"/> evaluate business method <evaluate expression="service.find()" result="viewScope.key"/> render view fragment <render fragments="body" /> Spring Framework - Web Flow Dmitry Noskov
  34. 34. Events flow  on-start  on-end state  on-entry  on-render (only for view)  on-exit transition Spring Framework - Web Flow Dmitry Noskov
  35. 35. Example<flow> <on-start> <evaluate expression="bookingService.createBooking(hotelId)" result="flowScope.booking" /> </on-start> <view-state id="enterBookingDetails" model="booking"> <on-render> <render fragments="body" /> </on-render> <transition on="proceed" to="reviewBooking" /> <transition on="cancel" to="cancel" bind="false" /> </view-state></flow> Spring Framework - Web Flow Dmitry Noskov
  36. 36. Business actions POJO<evaluate expression="service.businessMethod()" /> actionpublic class CustomAction implements Action { public Event execute(RequestContext context) {}}<evaluate expression="customAction" /> multi action Spring Framework - Web Flow Dmitry Noskov
  37. 37. Action state simple<action-state id="addBooking"> <evaluate expression="bookingService.addBooking()" /> <transition to="cancel"/></action-state> transitioning on evaluation<action-state id="cancelBooking"> <evaluate expression="bookingService.cancelBooking()" /> <transition on="cancelled" to="endState"/> <transition on="bookingNotFound" to="booking"/> <transition on-exception="org.swf.AccessDenied" to="booking"/></action-state> Spring Framework - Web Flow Dmitry Noskov
  38. 38. Event mappingReturn type Event identifierjava.lang.String the String valuejava.lang.Boolean yes / nojava.lang.Enum the enum nameany other type success Spring Framework - Web Flow Dmitry Noskov
  39. 39. Named actions<action-state id="callTwoMethods"> <evaluate expression="service.methodOne()"> <attribute name="name" value="methodOne" /> </evaluate> <evaluate expression="service.methodTwo()"> <attribute name="name" value="methodTwo" /> </evaluate> <transition on="methodTwo.success" to="showResults" /></action-state> Spring Framework - Web Flow Dmitry Noskov
  40. 40. Decision<decision-state id="hasItems"> <if test="service.hasItems()" then="checkItemsState" else="end" /></decision-state> Spring Framework - Web Flow Dmitry Noskov
  41. 41. Subflow<subflow-state id="addAccount" subflow="createAccount"> <transition on="accountCreated" to="reviewBooking"> <evaluate expression="bookingService.add(…)" /> </transition> <transition on="creationCancelled" to="end" /></subflow-state> Spring Framework - Web Flow Dmitry Noskov
  42. 42. Transition Spring Framework - Web Flow Dmitry Noskov
  43. 43. Advanced<transition on="cancel" on-exception="" to="cancel" bind="true" validate="true“ history="preserve/discard/invalidate"/> Spring Framework - Web Flow Dmitry Noskov
  44. 44. Global transition<global-transitions> <transition on="cancel" to="cancel" /></global-transitions> Spring Framework - Web Flow Dmitry Noskov
  45. 45. Finish Spring Framework - Web Flow Dmitry Noskov
  46. 46. End state simple<end-state id="cancel" /> custom view<end-state id="success" view="externalRedirect:controller?result=success"/> output<end-state id="bookingConfirmed"> <output name="bookingId" value="booking.id" /></end-state> Spring Framework - Web Flow Dmitry Noskov
  47. 47. Redirects servletRelative contextRelative serverRelative http:// or https:// Spring Framework - Web Flow Dmitry Noskov
  48. 48. FlowHandler Interfacepublic interface FlowHandler { public String getFlowId(); public MutableAttributeMap createExecutionInputMap(…); public String handleExecutionOutcome(…); public String handleException(…);} Bean<bean name="hotels/booking" class="test.BookingFlowHandler"/> Spring Framework - Web Flow Dmitry Noskov
  49. 49. Spring JS Spring Framework - Web Flow Dmitry Noskov
  50. 50. Configuration server side<mvc:resources mapping="/resources/**" location="/, classpath:/META-INF/web-resources/"/><mvc:default-servlet-handler /> client side<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> Spring Framework - Web Flow Dmitry Noskov
  51. 51. Simple decoration<form:input id="searchString" path="searchString"/><script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "searchString", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : {promptMessage : "Search hotels by name."} }));</script> Spring Framework - Web Flow Dmitry Noskov
  52. 52. Regexp<form:input path="creditCard"/><script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "creditCard", widgetType : "dijit.form.ValidationTextBox", widgetAttrs : { required : true, invalidMessage : "A 16-digit card number is required.", regExp : "[0-9]{16}" } }));</script> Spring Framework - Web Flow Dmitry Noskov
  53. 53. Date<form:input path="checkoutDate"/><script type="text/javascript"> Spring.addDecoration(new Spring.ElementDecoration({ elementId : "checkoutDate", widgetType : "dijit.form.DateTextBox", widgetAttrs : { datePattern : "MM-dd-yyyy", required : true } }));</script> Spring Framework - Web Flow Dmitry Noskov
  54. 54. Conclusion handles all navigation steps (including back, refresh) clear state management full integration with Spring MVC and other Spring Framework - Web Flow Dmitry Noskov
  55. 55. Books Spring Framework - Web Flow Dmitry Noskov
  56. 56. Links Web Flow reference http://static.springframework.org/spring- webflow/docs/2.3.x/reference/html/index.html samples https://src.springframework.org/svn/spring-samples/ forum http://forum.springframework.org/forumdisplay.php?f=36 Spring Web Flow 2 Web Development http://www.springsource.org/node/1286 Refcardz http://refcardz.dzone.com/refcardz/spring-web-flow Spring Framework - Web Flow Dmitry Noskov
  57. 57. Questions Spring Framework - Core Dmitry Noskov
  58. 58. The end http://www.linkedin.com/in/noskovd http://www.slideshare.net/analizator/presentations

×