VisualBuilder
  Home > Jsp > Tutorials > Conversion Model of JSF - 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
 Conversion Model of JSF
  << Prev: Creating the Reponse page for Registration Application Next: Example Continued For Conversion Model >>

A Java Server Faces application can be associated with the Java Bean known as backing bean, which we have just seen in the registration example. An application gets and sets the object data for a component by calling the appropriate object properties for that component. When a component is bound to an object, the application has two views i.e. Model View which represents the bean properties and the presentation view which actually displayed on the UI. The most of the development time and effort is wasted to show and maintain the data in both the layers in appropriate format. For example:- If with in the same application user want to display the date in different format then it is very cumbersome as he needs to code the different styles for different pages. The JSF conversion model implicitly convert the different data automatically.


The coming example will show the usefulness of the conversion model of the JSF. We take an example that a java.util.Date is coming from the backing bean and UI will display the dates in various formats. The tag <f:convertDateTime \ > is used to convert the date in various properties by just setting the attribute dateStyle with values. The following formats are available in the JSF:-



  • default:- Jan 07, 2008 2:35:45 PM ( Default Value)

  • short:- 01/07/08 22:55:42 PM

  • medium:- Jan 07, 2008 2:42:36 PM

  • long:- Jan 07, 2008 2:41:08 PM

  • full:- Monday, Jan 07, 2008 2:39:56 PM


Example:-


Step 1:-We need to create the seperate jsp i.e. dateFormat JSP for the example. The code for the jsp is as follows :-










<%@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">
<title>
JSP Page</title>
</head>
<body>
<f:view>
 <h:outputText value="
#{MyBean.today}">
   <f:convertDateTime type="
both" dateStyle="full"/>
 </h:outputText>
</f:view>
</body>
</html>




Step 2:- We need to create a backing bean to get the date from the bean to the UI. The code is as follows:-









package com.visualbuilder;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;


public class MyBean {


public Date getToday() {
   Calendar cal = java.util.Calendar.getInstance(Locale.US);
  return cal.getTime();
}


}




 


  << Prev: Creating the Reponse page for Registration Application Next: Example Continued For Conversion Model >>
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