February 17, 2019
Hot Topics:

Dissecting Java Page Flows

  • August 24, 2005
  • By Kunal Mittal & Srinivas Kanchanavally
  • Send Email »
  • More Articles »

Let's now look at a more detailed example. In this example, you'll extend the HelloWorld controller to actually have some basic "login" functionality.

Figure 1 shows the basic functionality you'll implement in the HelloWorld controller. For this example, you'll implement three actions—begin, processLogin, and showLogin—that go to three different JSPs. There's a login form where the user can fill in their username and password. When the user submits the form, they will be directed to success.jsp. Listing 5 shows the controller code for this simple Page Flow.

Figure 1. Basic login process in the HelloWorld controller

Listing 5. helloworld.jpf Extended for Login Functionality

import org.apache.beehive.netui.pageflow.PageFlowController;
import org.apache.beehive.netui.pageflow.annotations.Jpf;
import org.apache.beehive.netui.pageflow.Forward;
import helloworld.forms.LoginForm;

@Jpf.Controller (
      @Jpf.SimpleAction (name="cancel", path="begin.do")
public class HelloWorldController extends PageFlowController
@Jpf.Action (
      @Jpf.Forward (name="success", path="helloworld.jsp")
public Forward begin()
   return new Forward("success");

@Jpf.Action (
         @Jpf.Forward (name="success", path="login.jsp")
public Forward showLoginPage()
   return new Forward("success");}
      forwards ={
         @Jpf.Forward(name ="success", path ="success.jsp")
   public Forward processLogin(LoginForm form)
      System.out.println("User Name:"+form.getUsername());
      return new Forward("success");

To make this work, add just one line of code to helloworld.jsp:

<netui:anchor action="showLoginPage">Login</netui:anchor>

This translates to a link that the user can click in helloworld.jsp. This will trigger the showLoginPage action and take the user to login.jsp. Listing 6 shows login.jsp.

Listing 6. login.jsp

<%@page language="java" contentType="text/html;charset=UTF-8"%>
<%@taglib uri="http://beehive.apache.org/netui/tags-html-1.0"
            <netui:form action="processLogin">
            <p>User Name:
               <netui:textBox dataSource="actionForm.username"/>
               <netui:textBox dataSource="actionForm.password"
                  <netui:button type="submit">Submit
               <netui:button action="cancel">Cancel

The login JSP introduces the concept of a form. This is a basic form that looks a lot like a JavaBean or a Struts form class. It has basic getters and setters for the fields you've displayed in the JSP. NetUI and Page Flows provide automatic binding between the form variables and the JSP fields. Listing 7 shows the LoginForm class.

Listing 7. LoginForm.java

package helloworld.forms;
import org.apache.beehive.netui.pageflow.FormData;
public class LoginForm extends FormData
   private String username;
   private String password;
   public void setUsername(String name)
      this.username =name;
   public String getUsername()
      return this.username;
   public void setPassword(String password)
   public String getPassword()
      return this.password;

The example you've just seen is very basic. However, it will help you identify the different pieces of the Page Flow architecture.

Editor's Note: The second part of this article will appear after August 31st.

About the Authors

Kunal Mittal is a consultant specializing in Java technology, the J2EE platform, Web Services, and SOA technologies. He has coauthored and contributed to several books on these topics. Kunal works as an applications architect for the Domestic TV division of Sony Pictures Entertainment. In his spare time, he does consulting gigs for start-ups in the SOA space and for large companies looking to implement an SOA initiative. You can contact Kunal through his Web site at www.soaconsultant.com.

Srinivas Kanchanavally is a Software Architect with CoreObjects Software Inc. in Los Angeles, California. He has an in-depth under-standing of Java and J2EE. He also has vast experience designing large-scale J2EE application architectures. Srini has worked with Java, J2EE, Struts, WebLogic, and WebLogic Portal on client projects. And he has several years of experience working with various open-source frame-works and tools such as JBoss/Tomcat, MySQL, JUnit, and HTTPUnit.

Source of This Material

Pro Apache Beehive
By Kunal Mittal and Srinivas Kanchanavally

Published: August, 2005, Paperback: 240 pages
Published by Apress Press
ISBN: 1-59059-515-7
Retail price: $39.99
This material is from Chapter 4 of the book.

Page 3 of 3

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date