From scm-return-29820-apmail-geronimo-scm-archive=geronimo.apache.org@geronimo.apache.org Thu Jul 03 03:35:30 2008 Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 23206 invoked from network); 3 Jul 2008 03:35:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 3 Jul 2008 03:35:29 -0000 Received: (qmail 39589 invoked by uid 500); 3 Jul 2008 03:35:30 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 39545 invoked by uid 500); 3 Jul 2008 03:35:30 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 39536 invoked by uid 99); 3 Jul 2008 03:35:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Jul 2008 20:35:30 -0700 X-ASF-Spam-Status: No, hits=-1996.3 required=10.0 tests=ALL_TRUSTED,HTML_MESSAGE,MIME_HTML_ONLY X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 03 Jul 2008 03:34:40 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 04BAD234C14E for ; Wed, 2 Jul 2008 20:35:00 -0700 (PDT) Message-ID: <1577057028.1215056100014.JavaMail.www-data@brutus> Date: Wed, 2 Jul 2008 20:35:00 -0700 (PDT) From: confluence@apache.org To: scm@geronimo.apache.org Subject: [CONF] Apache Geronimo v2.1: User Interface development with JSF (page edited) MIME-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org

User Interface development with JSF has been edited by Phani Balaji Madgula (Jul 02, 2008).

(View changes)

Content:

JavaServer Faces technology provides

  • APIs for representing user interface components and managing their state, handling events triggered on them, validating inputs entered by user, defining page navigation, supporting internationalization and accessibility.
  • A custom tag library for developing JSF interface within a JSP.

JavaServer Faces is a flexible technology that uses the existing user interface and web tier mechanisms but it does not tie up the applications to a particular mark-up language, protocol and client device. It encapsulates various UI component functionality enabling it render data to various client devices by developing required custom tags. JavaServer Faces technology provides a custom renderer and a JSP custom tag library for rendering to an HTML client, allowing developers of Java Platform, Enterprise Edition (Java EE) applications to use JavaServer Faces technology in their applications.

JavaServer Faces technology clearly separates presentation logic from the application logic. Several development roles can be created and designated during the application development state. The JSF technology is developed through Java Community Process under JSR-127.

Apache geronimo v2.1 uses Apache MyFaces v1.2.2 for JSF implementation. This tutorial illustrates the following aspects of JSF.

  • Various UI components of JSF.
    (Text box, Combo box, Select box, Radio button, submit button)
  • Associating validations to UI components.
  • Configuring navigation rules using eclipse wizard.
  • Configuring JSF managed beans.
  • Associating managed bean actions to events.
  • Using JPA to persist the data captured in JSPs through managed beans.

The tutorial is divided into the following sections.

  • Setting the Eclipse environment
  • Creating WEB application with JSF configuration and entities
  • Setting up the database tables and the Datasource.
  • Deploying the (war) application
  • Running the application

In order to develop, deploy and run the application, the following environment is required.

  • Sun JDK 5.0+ (J2SE 1.5)
  • Eclipse 3.3.1.1 (Eclipse Classic package of Europa distribution), which is platform specific
  • Web Tools Platform (WTP) 2.0.1
  • Data Tools Platform (DTP) 1.5.1
  • Eclipse Modeling Framework (EMF) 2.3.1
  • Graphical Editing Framework (GEF) 3.3.1

The entire application can be downloaded from this link.

Setting the Eclipse environment

1. Download Apache Geronimo2.1 and install it on the server. Look into the geronimo documentation for instructions.

2. Install the eclipse IDE and download geronimo eclipse plugin and install it on top of eclipse. Look into the geronimo eclipse plugin documentation for instructions.

3. Create a runtime environment for Apache Geronimo2.1 in the eclipse. Look into the geronimo eclipse plugin documentation for instructions to install a runtime for Apache Geronimo2.1.

Creating WEB application with entities

1. Start the eclipse wizard and right click on the Project Explorer and click on the New => Dynamic Web Project

2. Enter the project name as EmployeeWEB and click on the Next button.

3. On the New Dynamic Web Project wizard, check on the Project Facet checkboxes and select the version values as below screen shot, and click on the Next button.

4. On the Web Module wizard, make sure that Generate Deployment Descriptor is checked as below and click on the Next button.

5. On the Geronimo Deployment Plan wizard, provide the moduleId values as below screen shot and click on the Next button.

6. On the JSF Capabilities wizard, check the second radio button and click on the New button
by the side of the combo box. This will open Create JSF Implementation Library wizard.
Provide the Library Name as MyJSFLibrary and add the following jars by
clicking on the Add button. Finally, click on the Finish button.

  • <geronimo_home>\repository\commons-beanutils\commons-beanutils\1.6.1\commons-beanutils-1.6.1.jar
  • <geronimo_home>\repository\commons-collections\commons-collections\3.1\commons-collections-3.1.jar
  • <geronimo_home>\repository\commons-digester\commons-digester\1.8\commons-digester-1.8.jar
  • <geronimo_home>\repository\commons-logging\commons-logging\1.0.4\commons-logging-1.0.4.jar
  • <geronimo_home>\repository\org\apache\myfaces\core\myfaces-api\1.2.2\myfaces-api-1.2.2.jar
  • <geronimo_home>\repository\org\apache\myfaces\core\myfaces-impl\1.2.2\myfaces-impl-1.2.2.jar

7. Now, on the JSF Capabilities wizard, add the URL Mapping Patterns as *.jsf and click on the Finish button.

8. This will create EmployeeWEB application in the Project Explorer as below screen shot.

9. Right click on the WEB-INF folder and navigate to New => Folder and create a folder by name tld as given in the screen shot below.

10. Copy myfaces_core.tld and myfaces-html.tld files into the tld folder. These *.tld files are available in the myfaces-api-1.2.2.jar file.

11. We are going to use JPA to connect to EmployeeDB database created in the embedded Derby database. JPA uses persistence.xml file for configuration. Create a META-INF folder in the EmployeeWEB => build => classes folder in the Project Explorer. The contents of the persistence.xml are as follows.

persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

 <persistence-unit name="Employee" transaction-type="JTA">  
  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  <non-jta-data-source>EmployeeDS</non-jta-data-source>
 </persistence-unit>
	
</persistence>

12. Right click on the EmployeeWEB and navigate to New => Class and create Employee.java as given in the below screen shot. Click on the Finish button after providing the values.

13. The contents of the com.jpa.sample.Employee are as follows. This is the entity class used with JPA for persistence.

com.jpa.sample.Employee
package com.jpa.sample;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "EMPLOYEE")
public class Employee {

 @Id
 public int empNo;
 public String empName;
 public String deptName;
 public String sex;
 public double salary;
 public String band;

 public int getEmpNo() {
  return empNo;
 }

 public void setEmpNo(int empNo) {
  this.empNo = empNo;
 }

 public String getEmpName() {
  return empName;
 } 

 public void setEmpName(String empName) {
  this.empName = empName;
 }

 public String getDeptName() {
  return deptName;
 }

 public void setDeptName(String deptName) {
  this.deptName = deptName;
 }

 public String getSex() {
  return sex;
 }

 public void setSex(String sex) {
  this.sex = sex;
 }

 public double getSalary() {
  return salary;
 }

 public void setSalary(double salary) {
  this.salary = salary;
 }

 public String getBand() {
  return band;
 }

 public void setBand(String band) {
  this.band = band;
 }

}

14. Similarly, create sample.jsf.Employee. The contents of the class are as follows. This is the managed bean used by JSF.

sample.jsf.Employee
package sample.jsf;

import java.util.ArrayList;

import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.transaction.UserTransaction;

public class Employee {

 public int empNo;
 public String empName;
 public String deptName;
 public String sex;
 public double salary;
 public String band;
 ArrayList<SelectItem> deptOptions;

 @PersistenceContext    
 private EntityManager em;

 public Employee(){

  deptOptions = new ArrayList<SelectItem>();
  
  SelectItem option = new SelectItem("Inventory", "Inventory");
  deptOptions.add(option);

  option = new SelectItem("Production", "Production");
  deptOptions.add(option);

  option = new SelectItem("Accounts", "Accounts");
  deptOptions.add(option);

  option = new SelectItem("Finance", "Finance");
  deptOptions.add(option);

  option = new SelectItem("Marketing", "Marketing");
  deptOptions.add(option);

  option = new SelectItem("IncomeTax", "IncomeTax");
  deptOptions.add(option);

  option = new SelectItem("Engineering", "Engineering");
  deptOptions.add(option);

 }

 public int getEmpNo() {
  return empNo;
 }

 public void setEmpNo(int empNo) {
  this.empNo = empNo;
 }

 public String getEmpName() {
  return empName;
 }

 public void setEmpName(String empName) {
  this.empName = empName;
 }

 public String getDeptName() {
  return deptName;
 }

 public void setDeptName(String deptName) {
  this.deptName = deptName;
 }

 public String getSex() {
  return sex;
 }

 public void setSex(String sex) {
  this.sex = sex;
 }

 public double getSalary() {
 return salary;
 }

 public void setSalary(double salary) {
  this.salary = salary;
 }

 public String getBand() {
  return band;
 }

 public void setBand(String band) {
  this.band = band;
 }

 public void addEmployee(ActionEvent event){

  com.jpa.sample.Employee employeeDup = 
    em.find(com.jpa.sample.Employee.class, this.empNo);
  
  if(employeeDup != null)
    throw new IllegalArgumentException
    ("Message : sample.jsf.Employee :
      Employee Already Exits ("+this.empNo+")");

  com.jpa.sample.Employee employee = 
   new com.jpa.sample.Employee();

  employee.setBand(this.band);
  employee.setDeptName(this.deptName);
  employee.setEmpName(this.empName);
  employee.setEmpNo(this.empNo);
  employee.setSalary(this.salary);
  employee.setSex(this.sex);

  try{

   Context ctx = new InitialContext();
   UserTransaction ut = 
       (UserTransaction)ctx.lookup("java:comp/UserTransaction");
   ut.begin();
   em.persist(employee);
   ut.commit();

  }catch (Exception e){
   throw new IllegalArgumentException
    ("Message : sample.jsf.Employee : Exception :"+e);
  }


}

 public void editEmployee(ActionEvent event){

 try{

  Context ctx = new InitialContext();
  UserTransaction ut = (UserTransaction)
         ctx.lookup("java:comp/UserTransaction");
  ut.begin();
  com.jpa.sample.Employee employee = 
    em.find(com.jpa.sample.Employee.class, this.empNo);
  employee.setBand(this.band);
  employee.setDeptName(this.deptName);
  employee.setEmpName(this.empName);
  employee.setEmpNo(this.empNo);
  employee.setSalary(this.salary);
  employee.setSex(this.sex);
  ut.commit();
 }catch (Exception e){
  throw new IllegalArgumentException
  ("Message : sample.jsf.Employee : Exception :"+e);
 }

 }

 public ArrayList<SelectItem> getDeptOptions() {
  return deptOptions;
 }

 public void setDeptOptions(ArrayList<SelectItem> deptOptions) {
  this.deptOptions = deptOptions;
 }

 public void retrieveEmployee(ActionEvent event){

  com.jpa.sample.Employee employeeDup = 
   em.find(com.jpa.sample.Employee.class, this.empNo);

  if(employeeDup == null)
  throw new IllegalArgumentException
   ("Message : sample.jsf.Employee : Employee does not exit ("+this.empNo+")");

  this.setBand(employeeDup.getBand());
  this.setDeptName(employeeDup.getDeptName());
  this.setEmpName(employeeDup.getEmpName());
  this.setEmpNo(employeeDup.getEmpNo());
  this.setSalary(employeeDup.getSalary());
  this.setSex(employeeDup.getSex());

 }

}

15. Right click on the EmployeeWEB project and create index.jsp as follows.

The contents of the index.jsp are as follows.

index.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
  <a href="/EmployeeWEB/addEmployee.jsf">
    <font size=4 color='blue'>
      Add employee details
    </font></a> <br/>

  <a href="/EmployeeWEB/RetrieveEmployee.jsf">
  <font size=4 color='blue'>
   Edit employee details
  </font></a> <br/>

</body>
</html>

16. Similarly, create addEmployee.jsp and the contents are as follows.

addEmployee.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/tld/myfaces-html.tld"  prefix="h" %>
<%@ taglib uri="/WEB-INF/tld/myfaces_core.tld"  prefix="f" %>  

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"
 +request.getServerName()+":"+request.getServerPort()+path+"/";
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 
 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" 
 content="text/html; charset=ISO-8859-1">
<base href="<%=basePath%>">

<script type="text/javascript">

</script>
<title>Add employee details</title>
</head> 
<body>

<f:view> 
 <h:form>

 <h:inputHidden id="id" value="#{Employee.empNo}"/>

 <h:panelGrid columns="2" border="0">

 <h:outputText value="Employee No :" />

 <h:inputText id="empNo" 
  value="#{Employee.empNo}" required="true">
 <f:validateLongRange maximum="100000" minimum="1"/>				     
 </h:inputText>


 <h:outputText value="Employee Name :" />

 <h:inputText id="empName" 
 value="#{Employee.empName}" required="true">
 <f:validateLength maximum="100" minimum="2"/>					     
 </h:inputText>

 <h:outputText value="Department Name :" />

 <h:selectOneMenu id="deptName" value="#{Employee.deptName}" 
  required="true" >
  <f:selectItems value="#{Employee.deptOptions}" />
 </h:selectOneMenu>

 <h:outputText value="Sex :" />

 <h:selectOneRadio id="sex" value="#{Employee.sex}" required="true">
 <f:selectItem id="male" itemLabel="Male" itemValue="male" />
 <f:selectItem id="female" itemLabel="Female" itemValue="female" />
 </h:selectOneRadio>

 <h:outputText value="Salary :" />

 <h:inputText id="salary" 
 value="#{Employee.salary}" required="true">
 <f:validateDoubleRange minimum="1000.00" maximum="10000000.00"/>					     
 </h:inputText>

  <h:outputText value="Employee Band :" />

  <h:selectOneListbox id="band" value="#{Employee.band}" size="3" required="true">
  <f:selectItem id="bandA" itemLabel="Band A" itemValue="A" />
  <f:selectItem id="bandB" itemLabel="Band B" itemValue="B" />
 <f:selectItem id="bandC" itemLabel="Band C" itemValue="C" />
 <f:selectItem id="bandD" itemLabel="Band D" itemValue="D" />
  <f:selectItem id="bandE" itemLabel="Band E" itemValue="E" />
  <f:selectItem id="bandF" itemLabel="Band F" itemValue="F" />
  </h:selectOneListbox>


  </h:panelGrid>

  <h:messages id="errors" 
  style="color:red;font-weight:bold" 
  layout="table" />

  <h:commandButton value="Save" 
   action="saveEmployee" 
   actionListener="#{Employee.addEmployee}" />


  </h:form>

 </f:view>

</body>
</html>

17. Similarly, create editEmployee.jsp and the contents are as follows.

editEmployee.jsp
<%@ page language="java" contentType="text/html;
 charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/tld/myfaces-html.tld"  prefix="h" %>
<%@ taglib uri="/WEB-INF/tld/myfaces_core.tld"  prefix="f" %>  

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+
  request.getServerName()+":"+
  request.getServerPort()+path+"/";
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 
 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" 
 content="text/html; charset=ISO-8859-1">
<base href="<%=basePath%>">
<title>Edit employee details</title>
</head> 
<body>

 <f:view> 
  <h:form>

   <h:inputHidden id="id" value="#{Employee.empNo}"/>

  <h:panelGrid columns="2" border="0">

  <h:outputText value="Employee No :" />

 <h:inputText id="empNo" disabled="true"
  value="#{Employee.empNo}" required="true">
  <f:validateLongRange maximum="100000" minimum="1"/>					     
  </h:inputText>


  <h:outputText value="Employee Name :" />

  <h:inputText id="empName" 
   value="#{Employee.empName}" required="true">
    <f:validateLength maximum="100" minimum="2"/>						     
  </h:inputText>

  <h:outputText value="Department Name :" />

  <h:selectOneMenu id="deptName" value="#{Employee.deptName}" required="true">
   <f:selectItems value="#{Employee.deptOptions}" />
  </h:selectOneMenu>

  <h:outputText value="Sex :" />

  <h:selectOneRadio id="sex" value="#{Employee.sex}" required="true">
   <f:selectItem id="male" itemLabel="Male" itemValue="male" />
   <f:selectItem id="female" itemLabel="Female" itemValue="female" />
  </h:selectOneRadio>

  <h:outputText value="Salary :" />

  <h:inputText id="salary" 
    value="#{Employee.salary}" required="true">
    <f:validateDoubleRange minimum="1000.00" maximum="10000000.00"/>	
  </h:inputText>

   <h:outputText value="Employee Band :" />

  <h:selectOneListbox id="band" value="#{Employee.band}" 
     size="3" required="true">
   <f:selectItem id="bandA" itemLabel="Band A" itemValue="A" />
   <f:selectItem id="bandB" itemLabel="Band B" itemValue="B" />
   <f:selectItem id="bandC" itemLabel="Band C" itemValue="C" />
   <f:selectItem id="bandD" itemLabel="Band D" itemValue="D" />
   <f:selectItem id="bandE" itemLabel="Band E" itemValue="E" />
  <f:selectItem id="bandF" itemLabel="Band F" itemValue="F" />
  </h:selectOneListbox>


  </h:panelGrid>

  <h:messages id="errors" 
    style="color:red;font-weight:bold" 
   layout="table" />

   <h:commandButton value="Save" 
   action="saveEmployee" 
   actionListener="#{Employee.editEmployee}"  />


   </h:form>
  </f:view>
</body>
</html>

18. Similarly, create RetrieveEmployee.jsp and the contents are as follows.

RetrieveEmployee.jsp
<%@ page language="java" contentType="text/html; 
 charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page language="java" %>

<%@ taglib uri="/WEB-INF/tld/myfaces-html.tld"  prefix="h" %>
<%@ taglib uri="/WEB-INF/tld/myfaces_core.tld"  prefix="f" %>  

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+
request.getServerName()+":"+request.getServerPort()+path+"/";
%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 
 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
  charset=ISO-8859-1">
<base href="<%=basePath%>">
<title>Add employee details</title>
</head> 
<body>

 <f:view> 
  <h:form>
   <h:panelGrid columns="2" border="0">

  <h:outputText value="Employee No :" />

 <h:inputText id="empNo" 
  value="#{Employee.empNo}">
  </h:inputText>

  </h:panelGrid>

<h:messages id="errors" 
style="color:red;font-weight:bold" 
layout="table" />

<h:commandButton value="Retrieve" 
action="retrieveEmployee" 
actionListener="#{Employee.retrieveEmployee}" />

<h:commandButton value="Cancel" 
action="cancel"/>


  </h:form>
 </f:view>
</body>
</html>

19. Open the geronimo-web.xml and replace the existing contents with the following contents. We explain the contents later when creating the datasource.

geronimo-web.xml
<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1" 
 xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
  xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" 
  xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
 
  <sys:environment>
   <sys:moduleId>
    <sys:groupId>EmployeeJSF</sys:groupId>
    <sys:artifactId>WEB</sys:artifactId>
    <sys:version>1.0</sys:version>
    <sys:type>car</sys:type>
  </sys:moduleId>

 <dependencies>
  <dependency>
   <groupId>console.dbpool</groupId>
   <artifactId>EmployeeDS</artifactId>
  </dependency>
 </dependencies>

 </sys:environment>

 <context-root>/EmployeeWEB</context-root>
</web-app>

20. Click on the faces-config.xml to open Faces Configuration Editor.

21. Click on the ManagedBean tab below and Click on the Add button.
This will open New Managed Bean Wizard.

22. Click on the browse button and search for sample.jsf.Employee class and click on the OK button.

23. Click on the Next button on the New Managed Bean Wizard. On the next screen, select Scope as request and click on the Next button.

24. Click on the Next button and finally, click on the Finish button. This will bring up the following screen shot as below.

25. Click on the Navigation Rule tab and move the mouse over Palette to bring it to the front.

26. Click on the Page and move the mouse over main area and click once. This will bring up Select JSP File wizard. Select the index.jsp and click on the OK button.

27. Similarly, add other JSPs also to the main area as follows.

28. Bring the Palette to the front and click on the Link.

  • Place the mouse on addEmployee.jsp on the main area and click once
    and move it to index.jsp and click once.
  • Similarly, click the mouse over RetrieveEmployee.jsp
    and move the mouse to index.jsp and click once.
  • Click the mouse over RtrieveEmployee.jsp and
    move the mouse over editEmployee.jsp and click once.
  • Click the mouse over editEmployee.jsp and move the
    mouse over RetrieveEmployee.jsp and click once.

The above actions create navigation rules and look like the screen shot below.

29. Press the escape button once and click on the link between addEmployee.jsp and index.jsp.
On the Properties window at the bottom, go to the From Outcome textbox
and provide the value as saveEmployee.

30. Similarly, Click on the link between RetrieveEmployee.jsp and index.jsp, and on the Properties window at the bottom, go to the From Outcome textbox and provide the value as cancel.

32. Similarly, Click on the link between RetrieveEmployee.jsp and editEmployee.jsp, and on the Properties window at the bottom, go to the From Outcome textbox and provide the value as retrieveEmployee.

33. Similarly, Click on the link between editEmployee.jsp and RetrieveEmployee.jsp, and on the Properties window at the bottom, go to the From Outcome textbox and provide the value as saveEmployee.

34. Click on the Source button to view the XML content generated out of these navigations rules and configuration. The contents should be as follows.

faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>

<faces-config
 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
 version="1.2">

  <navigation-rule>
   <description>Add Employee</description>
   <from-view-id>/addEmployee.jsp</from-view-id>
   <navigation-case>
    <from-outcome>saveEmployee</from-outcome>
    <to-view-id>/index.jsp</to-view-id>
   </navigation-case>
 </navigation-rule>


  <navigation-rule>
   <description>Retrieve Employee</description>
   <from-view-id>/RetrieveEmployee.jsp</from-view-id>
   <navigation-case>
    <from-outcome>retrieveEmployee</from-outcome>
    <to-view-id>/editEmployee.jsp</to-view-id>
   </navigation-case>
 </navigation-rule>

  <navigation-rule>
    <description>Retrieve Employee</description>
    <from-view-id>/RetrieveEmployee.jsp</from-view-id>
    <navigation-case>
     <from-outcome>cancel</from-outcome>
      <to-view-id>/index.jsp</to-view-id>
     </navigation-case>
 </navigation-rule>

  <navigation-rule>
    <description>Edit Employee</description>
    <from-view-id>/editEmployee.jsp</from-view-id>
    <navigation-case>
      <from-outcome>saveEmployee</from-outcome>
      <to-view-id>/RetrieveEmployee.jsp</to-view-id>
 </navigation-case>
</navigation-rule>


  <managed-bean> 
    <description>
     Employee Bean
   </description>
   <managed-bean-name>Employee</managed-bean-name>
   <managed-bean-class>sample.jsf.Employee</managed-bean-class>
   <managed-bean-scope>request</managed-bean-scope> 
  </managed-bean>


</faces-config>

35. This finishes the WEB application creation and JSF configuration. Export the EmployeeWEB to a EmployeeWEB.war file.

Setting up the database tables and the Datasource

1. Start the geronimo server and click on the Console Navigation => Embedded DB => DB manager. Enter EmployeeDB in the Create DB textbox as shown in the below screen shot and click on the Create button.

2. Create Employee table by entering the below SQL statement and clicking on the Run SQL button as shown in the below screen shot.

3. Click on the Console Navigation => Services => Database Pools, and click on the Using the Geronimo database pool wizard link to create a new datasource.

4. On the next screen, enter EmployeeDS in the Name of Database Pool textbox and select Derby embedded in the Database Type combo box. Click on the Next button.

5. On the next screen, select the configuration in the Driver JAR select box and enter EmployeeDB in the Database Name textbox, and click on the Deploy button at the bottom.

6. This will deploy the EmployeeDS database pool. The moduleId of the database pool is console.dbpool/EmployeeDS/1.0/rar which is declared as a dependency in the geronimo-web.xml. This is because, JPA uses this database source to persist entities.

Deploying the (war) application

1. Deploy the EmployeeWEB.war file using the command prompt as follows.


C:\Geronimo-2.1\bin>deploy.bat --user system --password manager deploy EmployeeWEB.war
Using GERONIMO_BASE:   C:\Geronimo-2.1
Using GERONIMO_HOME:   C:\Geronimo-2.1
Using GERONIMO_TMPDIR: var\temp
Using JRE_HOME:        C:\SDK-May-31-2007\jre
    Deployed EmployeeJSF/WEB/1.0/car @ /EmployeeWEB

Running the application

1. Open a browser window and hit the URL http://localhost:8080/EmployeeWEB/. This will bring up the below screen.

2. Click on the Add employee details link to get the below screen to add employees into the database. Just click on the Save button without entering any values. The JSF complains with validation errors as below.

3. Enter the values as given in the screen below and click on the Save button. This will take back to the main page.

4. Click on the Edit employee details link to get the below screen. Enter Employee No value as 10 and click on the Retrieve button.

5. This will bring up the details of the employee whose employee number is 10. We can edit the values as required and click on the Save button.