Java Reference
In-Depth Information
Each xmlns attribute has a name and a value separated by an equal sign ( = ). The following
declaration (line 5)
xmlns
xmlns="http://www.w3.org/1999/xhtml"
specifies that any unqualified tag names are defined in the default standard XHTML
namespace.
The following declaration (line 6)
xmlns:h="http://xmlns.jcp.org/jsf/html"
allows the tags defined in the JSF tag library to be used in the document. These tags must have
a prefix h .
An html element contains a head and a body. The h:head element (lines 7-9) defines an
HTML title element. The title is usually displayed in the browser window's title bar.
A h:body element defines the page's content. In this simple example, it contains a string
to be displayed in the Web browser.
h:head
h:body
Note
The XML tag names are case sensitive, whereas HTML tags are not. So, <html> is
different from <HTML> in XML. Every start tag in XML must have a matching end tag,
whereas some tags in HTML do not need end tags.
You can now display the page in index.xhtml by right-clicking on index.xhtml in the pro-
jects pane and choose Run File . The page is displayed in a browser, as shown in FigureĀ 33.5.
F IGURE 33.5
The index.xhtml is displayed in the browser.
33.2.3 Managed JavaBeans for JSF
JSF applications are developed using the Model-View-Controller (MVC) architecture, which
separates the application's data (contained in the model) from the graphical presentation (the
view). The controller is the JSF framework that is responsible for coordinating interactions
between view and the model.
In JSF, the facelets are the view for presenting data. Data are obtained from Java objects.
Objects are defined using Java classes. In JSF, the objects that are accessed from a facelet are
JavaBeans objects. A JavaBean class is simply a public Java class with a no-arg constructor.
JavaBeans may contain properties. By convention, a property is defined with a getter and a
setter method. If a property only has a getter method, the property is called a read-only prop-
erty. If a property only has a setter method, the property is called a write-only property. A
property does not need to be defined as a data field in the class.
Our example in this section is to develop a JSF facelet to display current time. We will cre-
ate a JavaBean with a getTime() method that returns the current time as a string. The facelet
will invoke this method to obtain current time.
Here are the steps to create a JavaBean named TimeBean .
JavaBean
 
 
Search WWH ::




Custom Search