Sunday, January 26, 2014

Spring Course: V148 - V159 Spring Webflow

Video 148: Introducing Webflow
you use it to define a sequence of steps.

Video 149: Creating a Flow Registery

1- add spring-webflow dependency
2- add webflow-config namespace in your beans.xml

3- add webflow-config:flow-registry

here you set the base-path, which is the folder that will have the workflow definintion which is an xml file.
flow-location is the workflow file name,

4- add contact-flow.xml
when we define a flow, we basically define states in view-state, we will do that in the next tutorial

Video 150: Hooking Up URLs to Webflows
Here we will add all the required beans 

These are things that you should remember, 
1- FlowRegistry
2- FlowExecutor 

as you can see the id "message" will be used in the url, so to start the workflow you go to ..../message

Video 151: Connecting Webflow and Apache Tiles
as you remember the contact-flow.xml looks like this

the view-state means jsp pages, so showContactForm should be a jsp page.

so, from the previous tutorial if you go to the url ..../message, it will go to the first page showContactForm.jsp

we should create this page, however to be able to use Apache Tiles with these pages you should add couple of extra beans

tilesViewResolver has been defined in previous videos.

now you can use Apache Tiles in your webflow pages.

In apache tiles definition we should add
as you can see showContactForm will redirect me to contact.jsp

Video 152: Creating a "Messages" Table
Nothing here, we added a Message table in the database, we will use it later

Video 153: Creating a Message Class
Here we added a Message Entity Class, and MessagesDao for database operations, we will use these classes later

Video 154: Adding a Message Form
as you remember before, we said that the workflow view state showContactForm will redirect us to contact.jsp

here we will define the contact.jsp page, which is going to contain a form

as you remember, we start the form by going to url ..../message, so we want the form to submit back to the same page, that is why we have commandName = message

you need also to add the hidden field _flowExecuationKey

Video 155: Transition
so now lets say we want to move from one page to another 
1- you add this in your workflow 
as you can see we define a transition on event send to go to the next state,

now we should add this

we added a hidden field to set the _eventId to send
now when we press the button we move to another state (another jsp page).

Video 156: Action States 
in the previous tutorials we were defining view states in our workflow, view state will move us from one page to another, 
here we will add Action State, in action state you can run code before moving to another page

as you can see, in the expression you write the name of the function that you want to execute, in this case it is the sendMessage() in the userService class.

Video 157: Linking to Webflows
Nothing much here, we did one thing.

as you can see we have a message object, and we set the value of username for this object

Video 158: Validating Webflow Forms

in order to validate the form in webflow we should add this

Video 159: Accessing User Details in Webflow
lets say you want to access user information, you can use the currentUser variable which comes with webflow

the usersService.getUser() is a function we defined, and we pass currentUser?.name, the question mark is used to check if currentUser is null or not (we talked about this before).

No comments:

Post a Comment