The last class we will include in our project is the Seat bean, known from the previous
chapter, which will be used as our model without any change (remember to include it in
your project with a proper package).
Building the view
Once we have coded the server side of our example, creating the front end will be quite
easy, as we have made all our resources available through CDI Beans.
One notable difference between some of the earlier editions of this topic is that Facelets
are now the preferred view technology for JSF. Earlier versions of JSF used JavaServer
Pages ( JSP ) as their default view technology. As JSP technology predates JSF, using JSP
with JSF sometimes felt unnatural or created problems. For example, the life cycle of
JSPs is different from the life cycle of JSF.
Compared to the simpler request-response paradigm on which the JSP life cycle is based,
the JSF life cycle is much more complex since the core of JSF is the MVC pattern, which
has several implications. User actions in JSF-generated views take place in a client that
does not have a permanent connection to the server. The delivery of user actions or page
events is delayed until a new connection is established. The JSF life cycle must handle
this delay between event and event processing. Also, the JSF life cycle must ensure that
the view is correct before rendering it, and also that the JSF system includes a phase to
validate inputs and another to update the model only after all the inputs pass validation.
Most of the time Facelets are used to build JavaServer Faces views using HTML-style
templates and component trees. Templating is a useful feature available with Facelets that
allows you to create a page that will act as the template for the other pages in an applica-
tion (something like Struts Tiles). The idea is to obtain portions of reusable code without
repeating the same code on different pages.
So here's the main application structure that contains a template page named de-
fault.xhtml that is referenced by views in the template attribute of the page's com-
position element. The template contains two main HTML div elements that will be used
to contain the main application panel ( content ) and a footer div ( footer ), which will
barely output the application title.
In order to add the template at first, add a new JSF page to the WEB-INF/templates
folder of your application and name it default.xhtml :
Search WWH ::