Java Reference
In-Depth Information
TimeBean
is a JavaBeans with the
@Named
annotation, which indicates that the JSF frame-
work will create and manage the
TimeBean
objects used in the application. You have learned
to use the
@Override
annotation in Chapter 11. The
@Override
annotation tells the com-
piler that the annotated method is required to override a method in a superclass. The
@Named
annotation tells the compiler to generate the code to enable the bean to be used by JSF facelets.
The
@RequestScope
annotation specifies that the scope of the JavaBeans object is within
a request. You can also use
@ViewScope
,
@SessionScope
or
@ApplicationScope
to
specify the scope for a session or for the entire application.
@RequestScope
33.2.4 JSF Expressions
We demonstrate JSF expressions by writing a simple application that displays the current
time. You can display current time by invoking the
getTime()
method in a
TimeBean
object
using a JSF expression.
To keep index.xhtml intact, we create a new JSF page named CurrentTime.xhtml as
follows:
Step 1. Right-click the
jsf2demo
node in the project pane to display a context menu and
choose
New
,
JSF Page
to display the New JSF File dialog box, as shown in Figure 33.9.
Step 2. Enter
CurrentTime
in the File Name field, choose Facelets and click
Finish
to
generate CurrentTime.xhtml, as shown in Figure 33.10.
Step 3. Add a JSF expression to obtain the current time, as shown in Listing 33.3.
Step 4. Right-click on CurrentTime.xhtml in the project to display a context menu and
choose
Run File
to display the page in a browser as shown in Figure 33.1.
F
IGURE
33.9
The New JSF Page dialog is used to create a JSF page.
L
ISTING
33.3
CurrentTime.xhtml
1 <?xml version='1.0' encoding='UTF-8' ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"
Search WWH ::
Custom Search