Introducing Java Page Flow Architecture
This article pick up where our earlier article, Dissecting Java Page Flows ended. In the following sections, we'll talk about the basic architecture and components that make up Java Page Flows and the NetUI tags.
Page Flow Components
The different components of a Page Flow are as follows:
- Form classes
The Jpf.Controller annotation is the meat of a Page Flow. It's just a file that contains Java code and annotations. The extension of this file is .jpf. As you saw in the previous example, a controller consists of several actions. This is unlike Struts—where one action is one class. You can think of a controller as a collection of action classes. The different annotations of a Page Flow are as follows:
- Jpf.Catch : Exceptions that the controller catches. We always recommend catching at least the Exception class to handle any unexpected/unhandled exceptions.
- Jpf.Forward : The different forwards. Each action has one or many forwards.
- global forwards: Any global forwards. For example, when an exception is caught, you might need a global forward. We always recommend having at least one of these go to some error page when an exception is thrown, as described in the Jpf.Catch item.
- boolean loginRequired: Does this controller require the user to be logged in to execute the actions defined in this Page Flow?
- Jpf.MessageResource  messageResources: Which message resources to use for error messages. This is similar to the Struts message resources.
- Jpf.MultipartHandler multipartHandler: Does this controller need to access multipart forms?
- boolean nested: Is this Page Flow a nested Page Flow?
- boolean readOnly: The actions do not modify any member variables.
- String  rolesAllowed: The roles that can access actions in this Page Flow.
- Jpf.SimpleAction  simpleActions: The simple actions in this Page Flow.
- boolean singleton: Is this Page Flow a singleton?
- String strutsMerge: The location of the Struts merge file.
- Jpf.ValidatableBean  validatableBeans: The validation rules for the beans.
- String validatorMerge: The location of the ValidatorPlugIn merge file.
Caution: Since Apache Beehive is still in early development, we recommend looking at the Javadocs online for the latest and greatest list of methods and functionality. See http://incubator.apache.org/beehive/apidocs/classref_pageflows/index.html.
Figure 1. Class diagram of FlowController and PageFlowController
Let's look at a few of the methods that you might use more regularly than others:
- afterAction: This method is a callback that occurs after any user action method is invoked.
- beforeAction: This method executes before any action executes. It's sort of a preProcess method for an action.
- onCreate: This executes when the Page Flow is created; you can use it to initialize any instance variables for the Page Flow.
- onDestroy: This executes when the Page Flow is destroyed; you can use it to clean up any variables.
- onRefresh: This is specifically important in a portal environment when no action needs to be executed and you'd rather just render a previously displayed JSP.
- isNestable: This determines whether this Page Flow can be nested.
- isSingleton: This determines whether this Page Flow is a singleton.
Tip: As you start working with Page Flows, refer to the PageFlowUtils class. It provides a bunch of helper methods that you'll find useful.