JavaBeat
Search JavaBeat

JAVABEAT
home
articles
tips
QnA
Books
forums
ARTICLE TOPICS
All Articles
Java 5.0
Java 6.0
EJB 3.0
JCA
Struts
JSF
Spring
Groovy
JBoss Seam
Hibernate
Eclipse
JavaFx
Google Guice
J2ME
GWT
WebServices
AJAX
ARCHIVE
2007 | 12 11 10 09 08 07 06 05 04 03
2008 | 04 03 02 01
CERTIFICATION KITS
350 SCJP 1.5 Mock Exams
400 SCJP 1.6 Mock Exams
300 SCWCD 5.0 Mock Exams
300 SCBCD 5.0 Mock Exams
Enter email address:

Latest JavaBeat Articles Delivered by FeedBurner
OUR NETWORK
javabeat
planetoss
Sponsors
Java Jobs eCommerce software Get Ubuntu 8.04 Get FireFox 3.0  

Pages : 1 2 3

Using Converters in JSF

Author : Raja
Date : Sat Nov 10th, 2007
Topic : jsf  

1) Introduction

Java Server Faces provides a component-based event-driven model for User Interface Layer in a Web Application. JSF UI Components behave very similar to Swing Components in which case Events are made to trigger by the User and they are handled by appropriate Listeners. In this article, we will focus on Converters which remains an important aspect in converting the user input to the one that is stored in the Mode. This article won't provide the introductory details related to JSF and novice users are advised to have to a glance over this Introduction to Java Server Faces article on JavaBeat. This article will begin with explaining the need to have Converters in JSF Framework and then continue to discuss about the various Standard Converters that are available in-built with JSF. Then the final section will show you how to develop and register Custom Converters to a JSF Application.

2) Converters in JSF

Before getting into details, let us study the need and advantage of having JSF Converters in place. Let us take an example of a Web Application in which the User will be presented with a Web Page for entering the input values. The values entered by the User in all cases will be in string format. Even, when asked to enter numerical values like age or salary whatever is being passed on to the Server end will still be in String format. So, there must be some intermediary which will do the job of converting the string values into the type that is appropriate for the particular field value.

Say, for example, if the User Form contains fields for name, age, salary and date of birth. Obviously, the model object for this form will contain string, integer, double and date data-types for storing name, age, salary and date of birth respectively. So the Converters do the job of converting the user input. JSF already comes with a bunch of Standard Converters (which will be covered shortly) for most of the common conversion process. If you can't find a suitable converter that is very specific to your Application, then still you can define a Customized Converter that will do the job for you.

In techincal terms, the Apply Request Value Phase is the phase during which the conversion of values to their appropriate type will happen. If the conversion process succeeds, then the submitted values are validated against the Validators defined. If either Conversion or the Validation fails, then the form is re-displayed in which case the model values that are associated for each UI Component would not be updated. It gives a chance to the user to re-enter the values. If the user enters the right value, and if the Conversion and the validation succeeds, then the Model values are updated.

 
Pages : 1 2 3
 

Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat