MVC 1.0 in Java EE 8: Getting Started Using Facelets

DZone 's Guide to

MVC 1.0 in Java EE 8: Getting Started Using Facelets

A tutorial on using MVC with Facelets rather than JSP in Java EE 8.

· Java Zone ·
Free Resource

MVC 1.0 is an action-based Model-View-Controller web framework, which will be a part of the future of Java EE 8. This post summarizes what needs to be done in order to use Facelets instead of default JSP as a view technology for MVC framework.

How to Set Up Facelets With MVC

Although MVC is a fresh new framework, the default view technology used in most examples — JSP — is rather old and sometimes cumbersome. On the other hand, the older brother JSF already builds on more modern and flexible Facelets.

Fortunately, the MVC framework has been designed to support many alternative view technologies out of the box, including Facelets.

FacesServlet needs to be mapped to *.xhtml. All xhtml pages should reside inside WEB-INF/views folder inside the web application, where the MVC framework searches for view files.

Here is a snippet in web.xml:

        <servlet-name>Faces Servlet</servlet-name>
        <servlet-name>Faces Servlet</servlet-name>

And that’s it! Now, you can start writing pages using facelets and reference them by path, which ends in xhtml.

An example Hello facelet page in WEB-INF/views/hello.xhtml:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        <title>Facelet Title</title>

In order to display this page, just return "hello.xhtml" from the controller action and you’re done. The controller should also fill "hello" variable in the model.


Getting started with MVC framework is really easy once you understand the basics of JAX-RS and CDI. The only requirement is to run your application on one of the application servers that support Ozark reference implementation. It is also very easy to use various view technologies as alternatives to default JSPs.

MVC framework includes support for many view technologies and enables to plug in other technologies on top of it. Configuring Facelets required only to configure Faces servlet in web.xml — the same thing you need to do when setting up JSF.

For more details, see the oiginal article at my blog: http://itblog.inginea.eu

javaee8 ,mvc ,facelets

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}