VisualBuilder
  Home > Jsp > Tutorials > Using Managed Bean With JSF -2 - JSF Tutorial
Tell a friend
Link to us
Total Members
      Members: 84661
     
Sitemap Forum Chat
Home
JSF Tutorial Home
1 . Introduction to JSF
2 . Life Cycle of JSF Application
3 . JSF Releases
4 . Comparing JSF With Existing Web Technologies
5 . Steps To Create JSF Application Using NetBeans IDE
6 . Web.xml file
7 . First Hello World Application
8 . Running the Application
9 . Introduction To JSF Tag Libraries
10 . Form Designing With JSF
11 . Using Managed Bean With JSF -1
12 . Using Managed Bean With JSF -2
13 . Using Javascript to Validate Form
14 . Adding Navigation in JSF Application
15 . Creating the Reponse page for Registration Application
16 . Conversion Model of JSF
17 . Example Continued For Conversion Model
18 . Displaying the Data in Data Table
19 . Example Continued For Data Table
 
 
JSP Home
JSP Members (18709)
JSP Member Articles ( 11 )
JSP Discussion (71)
JSP Q & A ( 87 )
- JSP Ask Question
- JSP Questions
- JSP Unanswered Questions
JSP Resources
JSP Source Code (172)
JSP Articles (34)
JSP Blogs (333)
JSP Jobs (0)
JSP Components (10)
JSP Books (9)
JSP Websites (13)
JSP News (12)
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.Net Security,Internationalisation And Deployment
ASP.NET Tutorial
C# Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (451 )
Source Code (3275 )
Articles (359 )
Books (372 )
Components (1596 )
News (892 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise

Jsp jsf Tutorial
 Using Managed Bean With JSF -2
  << Prev: Using Managed Bean With JSF -1 Next: Using Javascript to Validate Form >>

Step 2:- Declaring the Bean class in the faces-config.xml file


The most important part of using bean is to define the bean in the faces-config.xml file with <managed-bean></managed-bean> tag. The following mapping for the RegistrationBean.java file file is defined in the xml file.









<?xml version='1.0' encoding='UTF-8'?>

<!-- =========== FULL CONFIGURATION FILE ================================== -->


<faces-config version="1.2"
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">


 <managed-bean>
  <managed-bean-name>RegistrationBean</managed-bean-name>
  <managed-bean-class>com.visualbuilder.RegistrationBean</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
 </managed-bean>


</faces-config>




Step 3:- Binding the Form Elements with the Bean properties.


The last step is to map the form elements with the bean properties. So that when user submit the form then it will bind set and get the values from the appropriate setter and getter methods. The binding is done with the unified EL language. The #{} in the value attribute will bind the set the values from the bean objects. The following is the code for the Registraton.jsp after mapping the values from the bean.









<%@page contentType="text/html"%>
<%@page
pageEncoding="UTF-8"%>

<%@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.
--%>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<h1 align="center"> Registration Page</h1>
</head>
<body>

<f:view>
<h:outputLabel value="#{RegistrationBean.exampleText}"/>
<h:form id="form1">
<table align="center">
<tr>
   <td>Name:</td>
   <td><h:inputText id="name" label="Name" value="#{RegistrationBean.name}"/></td>
</tr>
<tr>
   <td>Password:</td>
   <td><h:inputSecret id="password" label="Password" value="#{RegistrationBean.password}"/></td>
</tr>
<tr>
   <td>Retype Password:</td>
   <td><h:inputSecret id="password1" label="Retype Password" value="#{RegistrationBean.password1}"/></td>
</tr>
<tr>
   <td>Description</td>
   <td><h:inputTextarea id="description" rows="10" cols="30" value="#{RegistrationBean.description}"/></td>
</tr>
<tr>
  <td colspan="2" align="center"><h:commandButton id="submit" action="success" value="Submit" /></td>
</tr>
</table>


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




 


  << Prev: Using Managed Bean With JSF -1 Next: Using Javascript to Validate Form >>
Jsp Jsf Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
 
ADVERTISEMENT
Partner List
Code Project
ASP Alliance
More
 
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising