NetUI Page Flows: An Evolution of Struts
Pages: 1, 2, 3, 4, 5

Page Flows

Having looked at the complexity in managing a Struts application, let's take an inside look at Page Flows and what they offer. Beehive's NetUI Page Flows framework makes development and maintenance a lot easier and more manageable. Listing 3 is a Page Flow controller, often abbreviated to Java Page Flow (JPF), for the LoginProcessFlow application described earlier. The Page Flow framework replaces all the action classes and the configuration file with a single JPF file.

Listing 3. LoginPageFlowController.java

package comparison.pageflows;
import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.Forward;
import org.apache.beehive.netui.pageflow.annotations.Jpf;

public class LoginPageFlowController extends PageFlowController
{
    @Jpf.Action(
        forwards = { 
            @Jpf.Forward(name = "success", path = "/index.jsp")
        }
    )
    protected Forward begin()
    {
       //initial processing
       return new Forward("success");
    }

    @Jpf.Action(
        forwards = { 
            @Jpf.Forward(name = "success", path = "/mypage.jsp"),
            @Jpf.Forward(name = "failure", path = "/index.jsp")
        }
    )
    protected Forward login()
    {
        //authentication logic
        if(user_authenticated)
           return new Forward("success");
        else 
           return new Forward("failure")
    }

    @Jpf.Action(
        forwards = { 
            @Jpf.Forward(name = "success", path = "/confirm.jsp")
        }
    )
    protected Forward signup()
    {
        return new Forward("success");
    }

    @Jpf.Action(
        forwards = { 
            @Jpf.Forward(name = "success", path = "/begin.do")
        }
    )    
    protected Forward logOut()
    {
        return new Forward("success");
    }
}

Listing 3 clearly shows the difference in the development effort and maintenance required between Struts and Page Flows.

As mentioned earlier, JPF is annotation driven and does not require forwards to be declared in a configuration file. Page Flows leverage the Beehive framework to auto-generate configuration files based on the annotations, like @Jpf.Action, declared in the JPF. Listing 3 shows how all the actions are handled in a single JPF file along with the forwards declared easily in the form of annotations. For example, the begin action, on success, forwards to index.jsp. You can clearly see how logic is handled by actions, and forwards are handled by simple annotations declared above their place of use. Annotations can be declared both at the action level and the Page Flow level. Of the many annotations provided by Beehive, @Jpf.Forward, @Jpf.Controller, and @Jpf.Action are the most commonly used. Discussing all annotations is beyond the scope of this article. For more information, visit the Page Flow Annotations documentation.

While a Struts application requires action classes for each of the actions, a single JPF file will suffice to develop the application using Page Flows. Page Flows provide a simple, single-file programming model. Page Flows enable developers to become immediately productive in building sophisticated Web applications without the learning curve typically associated with Struts. This makes Page Flows more flexible when it comes to modifications driven by business rule changes.

Pages: 1, 2, 3, 4, 5

Next Page ยป