Download presentation
Presentation is loading. Please wait.
Published byNeil Lamb Modified over 9 years ago
1
Introduction to Spring Web Flow Andrew Petro Software Developer Unicon, Inc. Jasig 2011 Westminster, CO 23 May 2011 © Copyright Unicon, Inc., 2011. Some rights reserved. This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/http://creativecommons.org/licenses/by-nc-sa/3.0/us/
2
2 Spring Web Flow 1.How Spring Web Flow Fits 2.What's a Flow? 3.Spring Web Flow States 4.Forms
3
3 Why is Spring Web Flow important? uPortal 4 uses Spring Web Flow CAS uses Spring Web Flow Spring Web Flow as viable Portlet development framework Quickly build and maintain wizard / flow Web experiences with panache Forms, processes, registrations This is bread and butter self-service IT
4
4 How Spring Web Flow Fits
5
5 Sits atop Spring Framework / MVC Spring Web Flow works with the rest of the Spring Framework and Spring WebMVC Diagram credit: Spring Web Flow documentation
6
6 Purpose of Spring Web Flow Spring Web Flow is good at building flows Which just begs the question, really. Let me get at this another way...
7
7 Aside: Spring Framework Dependency Injection / Inversion of Control Utilities, templates, helpers For easing all aspects of Java development Especially Java Web development
8
8 The Hollywood Principle Image credit http://www.flickr.com/photos/loop_oh/4337804209/ CC-BY-NDhttp://www.flickr.com/photos/loop_oh/4337804209/
9
9 Don't Call Us, We'll Call You
10
10 Dependency Injection Write POJOs. JavaBeans. Spring wires together using XML or Annotations or Autowiring or … Stop calling static factories. Code becomes more reusable, more flexibly configurable, less repetitive,...
11
11 Editing Portlet Publications in uPortal 4 RC1 An example of a flow
12
12 Portlet Management
13
13 Select Portlet Type
14
14 Set basic portlet info
15
15 Portlet Parameters
16
16 Select Categories
17
17 Select Users and Groups
18
18 What's a flow anyway?
19
19 What's a flow? A flow is a multi-step experience More than one request in making up a logical whole
20
20 A flow - what Has a beginning (state) and an end (state) Has zero or more intermediary states Has transitions between these states Has its own scope Can conveniently remember state between these steps until the flow completes and your application is ready to process the whole result
21
21 Flows - why Re-use multi-step processes Revisit steps in flow Constrained by allowable state transitions Stateful! Flow-scoped state (might) make your application cleaner (not having to model and remember at the persistence/domain layer incomplete state)
22
22 Re-use subflows
23
23 Revisit steps in flow
24
24
25
25 States and Transitions Views, Decisions, Actions, and Subflows
26
26 View States Renders a view. By convention, a view with the same name as the id. So, “viewLoginForm.jsp”, e.g.
27
27 Transitions from a View Cancel
28
28 Decision States Boolean decision about what state is next
29
29 Action States
30
30 Subflow States
31
31 How it really works Start at a start-state Flow through zero or more action and decision states until you get to another view state. Render it. Repeat previous step. Eventually exit the flow.
32
32 Ending with a view
33
33 Ending with a redirect <end-state id=”redirectView” view=”externalRedirect:${requestScope.response.url}” />
34
34 Ending with return from subflow
35
35 Setting variables and invoking Java between and within states
36
36 Expression language
37
37 Storing result from expression
38
38 Where can I insert expressions? On flow start On state entry On view render On transition execution On state exit On flow end
39
39 Forms
40
40 Form Objects Form objects are POJOs JavaBean properties public String getFname() { return fname; } public void setFname(String name) { fname = name; }...
41
41 Binding forms to model Model Form fields bind to JavaBean properties of the model Java object.
42
42 Binding All properties bind by default Bindings can be explicitly declared You can also use a custom binder
43
43 Binding forms selectively to model...... Binder Only bind the properties you intend to bind!
44
44 Selectively bind on transitions Bind attribute on transition You might not bother binding on a cancel, or you might bind but not validate if partial progress completing model.
45
45 Select Portlet Type
46
46 Next without required field
47
47 But cancel doesn't require field
48
48 Binding forms to model Model Form fields bind to JavaBean properties of the model Java object.
49
49 Properties can be required
50
50 CAS login form
51
51 Required fields
52
52 Properties can be required
53
53 Validation Validator for model objects Or Validator for model-in-specific-state As in, you can program custom validators in Java
54
54 Selectively validate on transitions validate attribute on transition You might bind but not validate if you want to capture the user input but not prevent transition if the input is invalid.
55
55 Say I pick a portlet type
56
56 I fill out this form, but...
57
57 So I pick another portlet type
58
58 And my form data is right there.
59
59 Even though it's not valid
60
60 Selectively validate on transitions validate attribute on transition You might bind but not validate if you want to capture the user input but not prevent transition if the input is invalid.
61
61 PortletDefinitionForm public class PortletDefinitionForm implements Serializable { public String getFname() { return fname; } public void setFname(String name) { fname = name; }...
62
62 PortletDefinitionFormValidator public void validate BasicInfo (PortletDefinitionForm def, MessageContext ctx) { if (StringUtils.isEmpty(def.getFname())) { ctx.addMessage(new MessageBuilder().error().source("fName").code("fname.required").build()); } else if (!FunctionalNameType.isValid(def.getFname())) { ctx.addMessage(new MessageBuilder().error().source("fName").code("fname.invalid").build()); }...
63
63 Validate${viewState}() public void validate BasicInfo (PortletDefinitionForm def, MessageContext ctx) {... }
64
64 Scopes
65
65 Scopes Flash scope View Scope Flow Scope Conversation Scope
66
66 Flash scope Cleared when a view is rendered
67
67 View Scope Created when enter view-state Destroyed on exit view-state Useful for transient state for rendering the view That you might need on processing the event fired by the user interaction with the view Or that you need for re-rendering the view
68
68 Flow Scope Created when enter flow Destroyed on exit flow Useful for transient state within the flow
69
69 Conversation scope Persists across returns from subflows
70
70 Conclusions
71
71 Spring Web Flow in uPortal 4 Many administrative portlets in uPortal 4 implemented using Spring Web Flow
72
72 Spring Web Flow in CAS
73
73 Spring Web Flow for Portlet Dev Works with Spring PortletMVC
74
74 Spring Web Flow Web Development Quickly develop self-service web flows Update, maintain, and tweak these applications with panache
75
75 Contact Information Andrew Petro Software Developer Unicon, Inc. apetro@unicon.net www.unicon.netwww.unicon.net/blog/apetro
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.