Developing lightweight Java web applications with JSF, Facelets, JPA, Spring and Shale – Part 1: The Primer


What is this all about? (Motivation)

If you’ve ever dug deeper into developing web applications with JSF or have developed Java web applications in the past using other frameworks and libraries, e.g. Turbine, Velocity, Struts, etc., you will soon find that JSF itself has a a nice concept but provides only the most basic functionality.

In JSF itself you have a strict seperation of concerns and a nicely split MVC architecture, but for a fully fledged application that uses persistent data, pluggable components and a templating system, JSF on its own just isn’t enough.

You could now start creating a new Java 5 EE application, building several components (JPA, EJB, etc.), bundle them into an EAR file and deploy them to the Glassfish application server. But we won’t. Don’t misunderstand me: there’s nothing wrong with writing a full Java Enterprise application and I salute to those who do, but for most developers such a setup is just overkill (whereas a simple Servlet is not enough). But this series is about lightweight applications. Please note that “weightâ?? is not measured in bytes but in the amount of stuff you have to write to get things done.

This series describes a different approach to Java web applications and is inspired by the facesgoodies project developed by Matthias Wessendorf. This project is a kickstart project for developing JSF applications including Spring and Shale using the JPA persistence layer. Unfortunately it is not document very well and somewhat hard to understand for those who have never used Spring or configured a more complex web application or a persistence unit.

This series/tutorial is designed to help you design next generation web applications using modern, community supported technologies.

Take a look around (The libraries used)

Java Server Faces (JSF)

Since you need at least a basic understanding of JSF in order to understand this tutorial I will not go into further details when describing JSF. Let’s just say that Java Server Faces is the recommendable technology for developing web applications with Java. You can read more about JSF by reading the official documentation.

Facelets

Facelets is a templating library for use with JSF. All pages are written in pure XHTML by utilising the XML namespace features to add additional JSF or JSP libraries. Basically you define a couple of named placeholders in your template file(s) and fill them later on with page specific content. Facelets offers a simple API with not more than ten tags for use in your templates and pages. And believe it or not, you usually don’t need more than four of them. You can read more on Facelets by visiting the official project site, reading the documentation or the Inside JSF article series over at JSF Central.

Java Persistence API (JPA)

JPA is a standardized API specification for Java persistence. It allows you to create simple POJO beans and map them to the database of your choice by adding some simple annotations. Since JPA is only a specification, we will also need a library that implements this specification. You may choose from several implementation, the two most popular are Hibernate and Toplink. This tutorial will use Toplink Essentials, the library that comes bundled with the Glassfish application server.

Spring

Spring is a fully fledged, modular Java Enterprise framework. What does that mean? In this tutorial we will not use all modules offered by Spring. We will use the IoC container to reduce the applications complexity when it comes to configuring objects and services. It will also help us to design decoupled components that can be switched later against other implementations, giving us a more flexible design.

We want our application to run on simple Servlet containers such as Jetty or Tomcat, therefor we cannot let the application server manage our database connections and transactions. This functionality will instead be provided by the Spring DAO and the Spring Transaction module.

Spring is â?? contrary to many other open source projects â?? very well documented. You might consider reading the developer manual or at least parts of it.

Apache Shale

Shale is a set of modules that are built around the basic JSF implementation and enhance it by various features. For the beginning, we will only use Shale Core and Shale Views. Views provides the application with a real controller layer in accordance with the MVC principle, replacing the JSF “glue objectsâ?? proposed by many JSF tutorials.

Maven 2

In order to reduce the hassle of managing the classpath, dependencies, directories and other aspects of Java software development, this project will be built using Maven 2. You might consider making yourself familiar the way Maven works by reading the getting started documentation.

Tags: , , , , , , ,

, , , , , , ,

  1. Bisher keine Kommentare.
(wird nicht veröffentlicht)