Professional Documents
Culture Documents
Lecture 44
Any scripting language can be used to achieve the said objective. However, JavaScript
and VBScript are two popular options
If user forgets to provide name and/or enters a negative value, a message would be
displayed to the user that indicates what was went wrong? However, if user conforms to
requirements, he/she would be taken to another page that displays a greeting message.
Note: In this example, JavaScript semantics isn’t discussed over here as I am assuming
that you might be familiar with some scripting language. Otherwise,
www.w3schools.com is an excellent resource to learn about scripting languages
<HTML>
<HEAD>
} // end of function
<BODY>
<BR/>
Name: <INPUT type="text" name="name" size="30" />
<BR/> <BR/>
Age: <INPUT type="text" name="age" size="30" />
<BR/> <BR/>
<INPUT type="submit" value="Submit">
</FORM>
</BODY>
</HTML>
------------------
JSF technology simplifies building the user interface for web applications. It does this by
providing a higher-level framework for working with your web applications. Some
distinct features will be discussed provided by this technology. To begin with, have a
look on some popular existing frameworks
Tapestry
Another popular framework that is extensively used in the industry is Tapestry. It has
almost similar sort of problems as with Struts.
JavaServer Faces
A framework which provides solutions for:
– Representing UI components
– Managing their state
– Handling events
– Input validation
– Data binding
– Automatic conversion
– Defining page navigation
– Supporting internationalization and accessibility.
If you are familiar with Struts and Swing (the standard Java user interface framework for
desktop applications), think of JavaServer Faces as a combination of those two
frameworks. Like Swing, JSF provides a rich component model that eases event handling
and component rendering; and like Struts, JSF provides Web application lifecycle
management through a controller servlet
JSF UI Components
And some open course JavaServer Faces components are also available like:
For example, if you write a JSF code to create a button, you will write:
<h:commandButton value="Login“
actionListener=“#{customer.loginActionListener}”
action=“#{customer.login}” />
The value attribute specifies the text that appeared on the face of a button, the
actionListener attributes specifies to call the loginActionListener method
written somewhere in a Customer class if an event is triggered and on which to go next,
is decided by the login method of Customer class and given as a value of action
attribute. The method specified in action attribute should return a String value as
the returned String value is used in page navigation.
Note: Many IDE provides visual support for JSF so you can drag and drop components
instead of writing tedious coding for defining JSF components as shown above.
Sun Studio Creator® is a free open source IDE that provides visual support for
JSF and can be downloaded form Sun site. The code examples are also built using
this IDE.
User will provide a name in the text field and his/her name after appending “hello” to it,
would be displayed on the same page.
JSF Validators
Validators make input validation simple and save developers hours of programming. JSF
provides a set of validator classes for validating input values entered into input
components. Alternatively, you can write your own validator if none of the standard
validators suits your needs.
Some built-in validators are:
DoubleRangeValidator
Any numeric type, between specified maximum and minimum values
LongRangeValidator
Any numeric type convertible to long, between specified maximum and minimum
values
LengthValidator
Ensures that the length of a component's local value falls into a certain range
(between minimum & maximum). The value must be of String type.
It is actually a modified version of the last example. This time, we’ll make sure that user
couldn’t left blank the name field and must enter a name between ranges of 2 to 10
characters. If any condition fails, an appropriate message would be displayed.
These are JavaBeans defined in the configuration file and are used to hold the data from JSF
components. Managed beans represent the data model, and are passed between business logic and
pages. Some other salient features are:
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>myPackage.MyBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
The syntax of binding expressions is based on the JavaServer Pages (JSP) 2.0 Expression
Language. In JSP, expressions are delimited with "${}", but in JSF they are delimited
with "#{}".
JSF Navigation
Page navigation determines the control flow of a Web application. JSF provides a default
navigational handler and this behavior can be configured in configuration. However, you
can do it visually in most tools like Sun Studio Creator
Note: We have quickly breezed through the JSF technology essentials due to shortage of
time. You must explore it by yourself to excel on it. You can find the resources in
the last handout to acquire further skills.
----------------
References: