developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




Return in early January to see which technologies and products won.




Developer Jobs

Be a Commerce Partner














 


Developer News -
Shifts for Enterprise Linux, Green Networks in '09    December 26, 2008
Gifts for All in Linux 2.6.28    December 24, 2008
Merb Merges With Rails    December 24, 2008
Sun's Unwired Motherboard Plans    December 24, 2008
Free Tech Newsletter -

Dissecting Java Page Flows
By Kunal Mittal & Srinivas Kanchanavally

Go to page: Prev  1  2  3  

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 (
   simpleActions={
      @Jpf.SimpleAction (name="cancel", path="begin.do")
      }
   )
public class HelloWorldController extends PageFlowController
{
@Jpf.Action (
   forwards={
      @Jpf.Forward (name="success", path="helloworld.jsp")
      }
   )
public Forward begin()
{
   return new Forward("success");
}

@Jpf.Action (
      forwards={
         @Jpf.Forward (name="success", path="login.jsp")
         }
   )
public Forward showLoginPage()
{
   return new Forward("success");}
@Jpf.Action(
      forwards ={
         @Jpf.Forward(name ="success", path ="success.jsp")
      }
   )
   public Forward processLogin(LoginForm form)
   {
      System.out.println("User Name:"+form.getUsername());
      System.out.println("Password:"+form.getPassword());
      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"
          prefix="netui"%>
<netui:html>
   <head>
      <title>Login</title>
      <netui:base/>
   </head>
   <netui:body>
      <p>
         <p>
            <netui:form action="processLogin">
            <p>User Name:
               <netui:textBox dataSource="actionForm.username"/>
            <p>Password:
               <netui:textBox dataSource="actionForm.password"
                              password="true"size="20"/>
               <dataSource="actionForm.name"/>
               <p>
                  <netui:button type="submit">Submit
               </netui:button>
               <netui:button action="cancel">Cancel
               </netui:button>
            </netui:form>
         </p>
      </p>
   </netui:body>
</netui:html>

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)
   {
      this.password=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.

Go to page: Prev  1  2  3  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Architecture & Design Archives






internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers