Spring Web Flow – Concepts [Part 1]

In this post we will see the major concepts relates to Spring web flow. Spring flow is an approach to implement multi page flow web applications like shopping portal.  For example in shopping portal application a user may involve in the below steps.

  1. Login to the application
  2. Surf among the products
  3. Add needed products to the cart
  4. view/edit cart if needed
  5. Click checkout
  6. Provide contact information
  7. Payment
  8. End

As there are multiple pages involved in the shopping flow, the data needs to be carried throughout multiple pages. If we handle this task manually it will be tedious task. We will go out of our indented business logic. To implement these kinds of tasks easily Spring provides the web flow framework.

A flow is nothing but a set of tasks to be done in a particular order. In webflow it is an xml file which tells the exactly how this flow should works. If we configure our application flow in spring web flow, the data carrying portion as well as the page navigation issues will be taken care by spring web flow itself. We can concentrate on our business logic rather than spending time on working those mundane tasks.

Spring web flow can be configured only via xml file. Currently it is not feasible to configure via only java.

The first thing to setup a web flow is configuration. A flow configuration involves below major components. Let’s go through them.

Flow executor: Flow executor is responsible to drive the flow.  The syntax will be like below.

<flow:flow-executor id="flowExecutor"/>

Flow Registry: Flow registry is responsible to load the flow definitions. For example if all flows under folder WEB-INF/flows needs to be loaded it has to be configured like  below.

<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows">
<flow:flow-location-pattern value = "**/*-flow.xml"/> 

Here one important thing to note is the url path to the flow will be determined by the path of the flow location.  For example if the path of a flow is /WEB-INF/flows/order/order-flow.xml  then the id will be order  (relative to the base path.) So the flow will be triggered while accessing the url http://{url}/{contextpath}/order

Instead of the pattern the path of the flow file also can be configured. For example to load order-flow.xml flow it can be configured like below.

<flow:flow-registry id="flowRegistry"> <flow:flow-location path = "/WEB-INF/flows/order/order-flow.xml"/> </flow:flow-registry>

If the full path is specified then the filename will become the id of that flow. In the above case it will be order-flow . If id needs to be different from the path it can be specified with id attribute like below.

<flow:flow-location path = "/WEB-INF/flows/order/order-flow.xml" id="custom/path/flow"/>

As per the above code the flow will be triggered when the url {contextPath}/custom/path/ flow is entered.

Flow Handler Mapping : Like DispatcherServlet  for controller mapping, there is a class FlowHandlerMapping  for URL to flow mapping for web flow.

Flow Handler Adapter : Like Controllers for handling the requests, there is a class FlowHandlerAdapter  to handle the flow requests

The next important thing is the flow.  A Flow is an xml file which tells the exactly how this flow should works. A flow will have three major components.

  1. State
  2. Transition
  3. Data

State : As per the name it is the state of the flow, which means the flows should be in a state.  There are five types of states possible.

  1. View-state
    • To display some pages to the user
    • <view-state id=”welcome”/> will redirect to the view named welcome
    • <view-state id=”welcome” view=”success”/> will redirect to the view named success
    • <view-state id=”welcome” view=”success” model=”flowScope.paymentDetails”/> will redirect to the view named  success  with model attribute paymentDetails 

  2. Action-state
    • To execute logical conditions. The syntax will be like below.
      <action-state id="saveOrder">
          <evaluate expression="pizzaFlowActions.saveOrder(order)"/>
          <transition to="thankYou"/>
    • When flow reaches  the above state the method pizzaFlowActions.saveOrder(order)  will be executed and once done thankYou  state will be invoked.
  3. Decision-state
    • To decide which path to proceed based on particular condition. Can be of only two paths. Either True or false
      <decision-state id="checkDeliveryArea">
          <if test="pizzaFlowActions.checkDeliveryArea(customer.zipCode)" 
          then="addCustomer" else="deliveryWarning"/>
  4. Subflow-state
    • To trigger a sub-flow from the current flow. Once the sub-flow ends the current flow will resume
      <subflow-state id="order" subflow="pizza/order">
          <input name="order" value="order"/>
          <transition on="orderCreated" to="payment"/>
  5. End-state
    • To denote the end of the flow. Syntax will be like below.
    • <end-state id=”customerReady”/>
    • If this is the sub flow the parent flow will resume once this flow ends.
    • If this is not sub flow and has a view it will be rendered.
    • If view name is prefixed with externalRedirect:  it will redirect to that page outside the flow
    • If view name is prefixed with flowRedirect:  it will redirect to that page to another flow
    • If this is not sub flow and there is no view, then the flow will end and go to the first state of the flow as a new flow.

Transition: To move from one state to another state the transition element will be used.

  • It will be child element of the state elements view-state,subflow-state or action-state. The syntax will be like below.
  • <transition to=”customerReady”>  – If no on event is attached, it will be the default transition.
  • <transition on=”submit” to=”customerReady”>  – On submit event it will be fired
  • <transition on-exception=”org.span.server.UserNotFoundException” to=”registrationForm”>  – On UserNotfoundException  this event will be fired.
  •  Instead of repeating same transitions on multiple states we can use global transitions like below. It will be applied to all states by default.
       <transition on="cancel" to="endState"/>

Data: To store and pass data through out the flow the data elements will be used. The syntax will be <var name=”customer” class=”org.span.domain.Customer”/>

  • In the above example a new Customer object will be created and assigned to customer. Also will be available across all state in that flow
  • Also <evaluate>  can be used on a view state or action state like below
  • <evaluate result=”viewScope.toppingsList” expression=”T(org.span.domain.pizza.Topping).asList()”/>
  • Also <set>  can be used to set a variable’s value.
  • <set name=”flowScope.pizza” value=”new org.span.domain.Pizza()”/>
  • We can set the scope of the variables. It can be any one of the five types as below
    1. Conversion Scope     ->     Created at the top level and destroyed when top flow ends. Available under all sub flows too.
    2. Flow Scope               ->     Created at the flow level and available only within that level
    3. Request Scope         ->     Created when a request is made into a flow and destroyed when the flow returns
    4. Flash Scope              ->     Created when a flow starts and destroyed when flow ends. It is also cleared when a view state is rendered
    5. View Scope               ->     Created when a view state is entered, and destroyed when the state exists. Visible only to the view state.
  • Default scope of variable declared via <var>  tag will be flow scope.
  • Default scope of variable declared via <set> ,<evaluate>  will be mentioned along with the variable name like <set name=”flowScope.totalMarks” value=”499″/>

That is all about the major components of the web flow. Also web flow can be secured as well. To secure a flow it has to be configured like below.

<view-state id="restricted" view="paymentdetails">
    <secured attributes="ROLE_ADMIN,ROLE_FINANCE" match="all"/>

attributes  are comma separated roles. match  can be ‘any’ – At least one role required  or ‘all’ – All roles required .

In this section we have discussed the concepts of Spring web flow. In the next tutorial we will implement a simple web flow application to understand all the discussed concepts.

Posted in spring, Spring Web Flow | Tagged , | Leave a comment

Useful SVN Commands

svnadmin create REPOS_PATH - Create a new repositiry in the REPOS_PATH svnadmin create --fs-type fsfs /var/svn/repos - Create a new repositiry in the REPOS_PATH using fsfs system svnadmin create --fs-type bdb /var/svn/repos - Create a new repositiry in the REPOS_PATH using bdb system fsfs system - Changes noted against previous version bdb system - Changes noted against from initial version svn checkout URL - Creat a working copy of a repository svn add filename - To add file to working copy svn delete filename - To remove file from working copy svn copy foo bar - To make a copy of foo to bar and save it as svn change svn move foo bar - svn copy foo bar + svn delete foo svn mkdir dirname - To create a directory under working copy svn commit - Save the changes to svn repository with new revision svn commit --depth empty - Same as commit but only update the changes in the current level svn commit -m "message" - Same as commit but commits with message svn commit -f messageFile - Same as commit but commits with messag in messageFile svn update - Update Current working copy (Current path only, if need full update go to working copy home path) with HEAD version (U-updated, G-merged, C-Conflict) During conflict we can postpone the action. It will create multiple files with revision numbers. But before next commit have to resolve, otherwise cannot commit. svn resolve - If we postponed any conflicts to do svn resolve --accept working filename - accept my changed file as final copy and resolve svn resolve --accept theirs-full filename - accept HEAD version changed file as final copy and resolve svn status - Show the changes in the working copy from the initial checkout (No need connection to repository, with the help of .svn directory will be found) m-modified, a-added, d-deleted,c-conflict,?-not_in_svn svn status -v - Show all files versions even there is no change. svn status -v -u - Show all files versions by comparing with the repository HEAD version (Required connectivity to repository, * means change made to that file after checkout) svn diff - Show the content changes in detail for each file. (- deleted, + added) svn log - Shows comlete list of changes made to each revision for all files given file svn annotate filename - Full History of changes made to a file in line by line. svn revert filename - Revert the changes to working copy initial version. svn revert addedFile - Remove from Working Copy (check with svn status). svn revert deletedFile - Add back to Working Copy (check with svn status).

SVN Serve Setup

Note 1:
If we directly add directory or file to the working copy it will not be added to the repository when we commit. So either create directory or files directly the use command svn add file/directory name or create using svn add/ svn mkdir.

Posted in Others | Tagged | Leave a comment

Sublime Text 3 Shortcuts

Recently I came across this post for sublime Text 3 shortcuts. A very useful post.

Sublime Text 3 Shortcuts

Posted in Others | Leave a comment

word-wrap not working in ie

If you are trying to apply the css property word-wrap: break-word  to an anchor tag it will not get effect in internet explorer. To overcome this apply this property to the parent tag of the anchor tag.

For example from

   <a href="#" style="word-wrap:break-word">Link Text</a>


<p style="word-wrap:break-word">
   <a href="#">Link Text</a>


Posted in Others | Tagged | Leave a comment

Apache http server in detail – 1

To verify httpd installed or not

rpm -qa httpd
(will display the package details if available)
 ex: httpd-2.2.15-29.el6_4.x86_64

Default Paths

/usr/sbin/httpd         command path
/etc/httpd              httpd root path
/etc/httpd/conf         Main config path
/etc/httpd/conf.d       Additional config path
/etc/httpd/logs         Link pointed to httpd log & error log

 Default log files of Apache Webserver

access_log           All access details
error_log            All Error Details

To re-load the config/modules

service httpd reload

To start the httpd service

service httpd start

To stop the httpd service

service httpd stop

To restart the httpd service

service httpd restart

To check the status of the service

service httpd status

Default Declarations used in the configuration file

ServerRoot                Default Root location of httpd
PidFile                   id of the initial httpd server;Because apache will create by default 
                          additional child process to handle traffic
DocumentRoot              File System Root Directory
  •  All paths mentioned in the config file will be calculated from ServerRoot path (i.e) Relative path
  • Default error log will be calculated from the server root directory. If one wants the error log to be moved to another place, create log directory as a symbolic link to another required folder. (Ex /var/log/httpd/logs)

Number of Server instances needs to be started can be set up in the below section.

<IfModule prefork.c>
     StartServers       8
     MinSpareServers    5
     MaxSpareServers   20
     ServerLimit      256
     MaxClients       256
     MaxRequestsPerChild  4000

# StartServers: &nbsp;&nbsp; &nbsp;     number of server processes to start
# MinSpareServers:&nbsp;&nbsp; &nbsp;   minimum number of server processes which are kept spare
# MaxSpareServers: &nbsp;&nbsp;    maximum number of server processes which are kept spare
# ServerLimit: &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;    maximum value for MaxClients for the lifetime of the server
# MaxClients: &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;   maximum number of server processes allowed to start
# MaxRequestsPerChild:   maximum number of requests a server process serves


  • Directory tag                                 –    can be used to apply settings for particular directory.
  • DirectoryMatch tag                      –    Same as Directory tag but we can use patterns.(i.e) setting rules for multiple directories (ex)
    <DirectoryMatch "^/www/(.+/)?[0-9]{3}">

    would match directories in /www/ that consisted of three numbers.

  • Options FollowSymLinks                 –    Webpages under this directory can point to any files under / directory via symbolic link. (i.e) outside of www directoy
  • AllowOverride None                          –    If set that partiular directory configuration can be overridden via .htaccess file
  • Order allow deny / deny allow        –    The meaning is if we mentioned allow deny then first allow will be taken, then deny will be taken
    if we mentioned deny allow then first deny will be taken then allow will be taken
    What is the cause of this? For example if we give like below

    Order deny allow
    allow from all
    deny from

    the expectation is to deny only from But it will allow all people. Because we gave deny at first, allow later. So allow will over write deny order

  • Options Indexes                                   –    respond with directory listing if the index file not available. -Indexes (not allowed)  ,+Indexes (allowed)
  • Files Directive                                       –    similiar like Directory Directive; the difference is files directive is at file level where Directory directive is at directory level
  • FilesMatch directive                             –    similar like DirectoryMatch but for files
  • Location directive                                 –    similar like Files,Directory directives; but based on url config will be applied

    <Location /server-info>
    SetHandler server-info
    Order deny,allow
    Deny from all
    Allow from
Posted in Apache | Tagged , | Leave a comment

Useful Shortcut Commands for Aqua Data Studio


To Launch the SQL Query Window

To autocomplete the query

To launch the query builder

To exexute the query

To exexute the query to edit the result

To save the changes made to the DB

To Refresh the result set

To change the copied content to delimited content

To Format the queries

To select a particular word
Ctrl+Click on the word
Posted in Others, Tools | Tagged , , | 1 Comment