JAVA SERVER FACES (JSF)

JSF PROJECTS

JSF PROJECT 1

JSF Examples

JSF EXAMPLE

adplus-dvertising
Creating a Blank Application with JSF Support in NetBeans IDE
Previous Home Next

This tutorial demonstrates how JSF 2.0 support to a web application,

and adding JSF 2.0 framework support to a basic web application, and proceed by:

  1. wiring the managed bean to the application's web pages.
  2. creating a JSF managed bean to handle request data.

Requirement for such application:

  1. NetBeans IDE.
  2. Java Development Kit( JDK).
  3. A Web Server like Apache Tomcat, or GlassFish Server.
  4. JavaServer Face web application framework.

Setting up for a new blank JSF web application

Now following Steps involved in the how to create a simple JSF web application by using NetBeans IDE ( using Netbeans IDE 7.0 with default JSF version 2.0):-

Step 1: Start IDE --> choose New file( Ctrl+N) or New project( Shift+Crtl+N) button in the IDE's main toolbar.

Step 2: Choose Java Web--> Web Application option from New project and click Next.

Step 3: Add project name and click Next.

Step 4: Add web Server( like Apache Tomcat or GlassFish) in Application and click Next.

Step 5: Add Web FrameWork (JavaServer Face) in Default web application. After click the check box of JSF, JavaServer Faces configure dialog box will open as shown in figure. Then, click on registered libraries which provide all the necessary tagLibary and JSF default library into Web application.

Important thing is that user can also add custom Library, in replace of Register library

Step 6: Click the configure tab, add JSF configure into Web.xml file to specify how the Faces servlet is registered in the project's deployment descriptor, JSF page URL pattern and preferred page language( want Facelets or JSP pages to be the used with the project). Since JSF 2.0 support, Facelets and JSP two different type of language.

Step 7: Click on components tab, JSF also support Component suites in web application, used as a application needed. and then click Next.

Step 8: After adding all the information, your application open in your IDE with welcome page as a welcomeJSF.jsp

Step 9: Start your server, a small green run option appear in front of your server name, that mean your server must be start and ready to deployed your application.

Step 10: Welcome file which auto generated in web application.

<%--
   Name: welcomeJSF.jsp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%-- Tag Library --%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>r4r.co.in</title>
</head>
<body>
<h1><h:outputText value="Welcome to JavaServer Faces! First empty JSF Example"/></h1>
</body>
</html>
</f:view>

Step 11: web.xml file, which contain default JSF application configuration

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
   <context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- JSF Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<!-- Page url pattern -->
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<!-- first/welcome file of application  -->
<welcome-file>faces/welcomeJSF.jsp</welcome-file>
</welcome-file-list>
</web-app>

Run your Application:

Previous Home Next