JSF

JSF Tutorial
 JSF Tag Examples
 JSF Examples
JSF with JDBC Examples 
3). How to insert and retrieve data from database using JSF



What is JSF?

JavaServer Faces (JSF) is a MVC web framework that simplifies the construction of user interfaces (UI) for server-based applications by using reusable UI components in a page.JSF provides facility to connect UI widgets with data sources and to server-side event handlers. The JSF specification defines a set of standard UI components and provides an Application Programming Interface (API) for developing components.JSF enables the reuse and extension of the existing standard UI components.


JSF UI component model

JSF provides developers capability to create Web application from collections of UI components that can render themselves in different ways for multiple client types (for example HTML browser, wireless or WAP devise). 
JSF provides


  • Core library
  • A set of base UI components - standard HTML input elements
  • Extension of the base UI components to create additional UI component libraries or to extend existing components.
  • Multiple rendering capabilities that enable JSF UI components to render themselves differently depending on the client types

Benefits

JSF reduces the effort in creating and maintaining applications which will run on a Java application server and will render application UI on to a target client.JSF facilitates Web application development by





  • proving reusable UI components
  • making easy data transfer between UI components
  • managing UI state across multiple server requests
  • enabling implementation of custom components
  • wiring client side event to server side application code

JSF Environment setup

This tutorial will guide you on how to prepare a development environment to start your work with JSF Framework. This tutorial will also teach you how to setup JDK, Eclipse, Maven, and Tomcat on your machine before you setup JSF Framework:

System Requirement

JSF requires JDK 1.5 or higher so the very first requirement is to have JDK installed in your 
machine.

Setup Eclipse IDE

All the examples in this tutorial have been written using Eclipse IDE. So I would suggest you should have latest version of Eclipse installed on your machine based on your operating system.

To install Eclipse IDE, download the latest Eclipse binaries with WTP support from http://www.eclipse.org/downloads/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\eclipse on windows, or /usr/local/eclipse on Linux/Unix and finally set PATH variable appropriately.
Eclipse can be started by executing the following commands on windows machine, or you can simply double click on eclipse.exe 




 %C:\eclipse\eclipse.exe 



Eclipse can be started by executing the following commands on 
Unix (Solaris, Linux, etc.) machine: 



$/usr/local/eclipse/eclipse

After a successful startup, if everything is fine then it should display following result:




*Note: Install m2eclipse plugin to eclipse using following eclipse software update site
m2eclipse Plugin - http://m2eclipse.sonatype.org/update/.
This plugin enables developers to run maven commands within eclipse with embedded/external maven installation.




Download Maven archive

Download Maven 2.2.1 from http://maven.apache.org/download.html

OS
Archive name
Windows
apache-maven-2.0.11-bin.zip
Linux
apache-maven-2.0.11-bin.tar.gz
Mac
apache-maven-2.0.11-bin.tar.gz



Extract the Maven archive

Extract the archive, to the directory you wish to install Maven 2.2.1. The subdirectory apache-maven-2.2.1 will be created from the archive.


OS
Location (can be different based on your installation)
Windows
C:\Program Files\Apache Software Foundation\apache-maven-2.2.1
Linux
/usr/local/apache-maven
Mac
/usr/local/apache-maven

Set Maven environment variables

OS
Output
Windows
Set the environment variables using system properties. M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-2.2.1 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m
Linux
Open command terminal and set environment variables. export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1 export M2=%M2_HOME%\bin export MAVEN_OPTS=-Xms256m -Xmx512m
Mac
Open command terminal and set environment variables. export M2_HOME=/usr/local/apache-maven/apache-maven-2.2.1 export M2=%M2_HOME%\bin export MAVEN_OPTS=-Xms256m -Xmx512m



Add Maven bin directory location to system path

Now append M2 variable to System Path

OS
Output
Windows
Append the string ;%M2% to the end of the system variable, Path.
Linux
export PATH=$M2:$PATH
Mac
export PATH=$M2:$PATH



 Verify Maven installation

Now open console, execute the following mvn command

OS
Task
Command
Windows
Open Command Console
c:\> mvn --version
Linux
Open Command Terminal
$ mvn --version
Mac
Open Terminal
machine:~ joseph$ mvn --version

 Finally, verify the output of the above commands, which should be something as follows:


OS
Task
Windows
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530) Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre
Linux
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530) Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre
Mac
Apache Maven 2.2.1 (r801777; 2009-08-07 00:46:01+0530) Java version: 1.6.0_21 Java home: C:\Program Files\Java\jdk1.6.0_21\jre

Setup Apache Tomcat:

You can download the latest version of Tomcat from http://tomcat.apache.org/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\apache-tomcat-6.0.33 on windows, or /usr/local/apache-tomcat-6.0.33 on Linux/Unix and set CATALINA_HOME environment variable pointing to the installation locations.


Tomcat can be started by executing the following commands on windows machine, or you can simply double click on startup.bat

 





%CATALINA_HOME%\bin\startup.bat
 
 or
 
 C:\apache-tomcat-6.0.33\bin\startup.bat

Tomcat can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine:


$CATALINA_HOME/bin/startup.sh
 
or
 
/usr/local/apache-tomcat-6.0.33/bin/startup.sh

 After a successful startup, the default web applications included with Tomcat will be available by visiting http://localhost:8080/. If everything is fine then it should display following result:






Further information about configuring and running Tomcat can be found in the documentation included here, as well as on the Tomcat web site: http://tomcat.apache.org
Tomcat can be stopped by executing the following commands on windows machine:
  




%CATALINA_HOME%\bin\shutdown 
or 
C:\apache-tomcat-5.5.29\bin\shutdown
 
Tomcat can be stopped by executing the following commands on Unix (Solaris, Linux, etc.) machine:





$CATALINA_HOME/bin/shutdown.sh 
or 
/usr/local/apache-tomcat-5.5.29/bin/shutdown.sh




No comments:

Post a Comment