The folks at grassr.com have posted an introductory article on Grails and Webflow.

So this next look into grails development is meant to help people get to grips with webflows; to explain how to go from a conceptual diagram to real groovy code. So lets begin with a little introduction of the different types of state grails provides us with to build our webflows.

View State
A state of the webflow which just displays a page to the end user.

Action State
An action state has no view but performs some kind of action, effectively it is a code block that gets executed.

Action/View State
Somewhere in between the previously mentioned 2 is the action view state, which renders a view, but can also execute an action prior to moving onto the next state. This will be explained in greater detail below.

So using these types of state we are going to build this state diagram in groovy

State Diagram

The article continues by explaining each step as laid out in the diagram, pointing out default values and settings available through conventions, dispelling any gotchas that may hinder your progress in this scenario. This article is actually linked to a previous one titled Grails Gotchas, where they explain some issues you must take into account when creating webflows in Grails, issues like

Pageflows names have to be unique: give your pageflow unique names, you can always map them to a nicer url using the URLMapping configuration.

In pageflow actions you must use a transaction to perform a delete operation: wrap any calls to delete in a transaction

XML Library Problems: replace the packaged xml-apis.jar and xercesImpl.jar in the <grails_dist>/lib directory and then clean out my whole project and rebuild.

The Hibernate Context: the major problem they wer having is the security framework they were using (acegi) was loading the object in a different context to that of their main application. Which meant when they tried to load collections of a user which desirably would be lazy loaded they were receiving exceptions from hibernate.Their solution was to just store the username as the principal in the session object and rely on the hibernate caching mechanism to stop this from hitting the database every time.

Read the while article at State Diagram to Grails Webflow.

Tags:



Leave a Comment