Saturday, February 6, 2010

Wizards in a stateless web

Maintaining the information gathered throughout the steps of a wizard can be challenging for a website. We will here explore an approach which relies on the back end database.

Suppose our website provides a wizard for creating customers. The first step would be responsible for gathering the customer's name. When posted, the first form will be sent to the BeginCustomer service, which will insert a row in the PendingCustomer table, returning the generated ID.

The second step would be responsible for gathering the customer's address. When displayed, the second form will invoke the GetNewCustomerAddress service with the previously generated PendingCustomerID. Given that no address has yet been entered, it will initially appear empty.

When posted, the second form will invoke the SetNewCustomerAddress service with the PendingCustomerID. The service will insert a row in the PendingCustomerAddress table.

Should the second step be redisplayed through the back button, the GetNewCustomerAddress service will be reinvoked. This time, the second step will display the previously entered address. And should the second step be reposted, the SetNewCustomerAddress service will overwrite the values in the PendingCustomerAddress table.

Finally, when the wizard is completed, the final form post will invoke the CommitNewCustomer service. The service will validate the information saved in the pending tables, transfer this information to the real tables, and delete it from the pending tables. From then on, the PendingCustomerID will be invalid, making it impossible to get back to the wizard steps.