About the JPlates examples

This section of the website is dedicated to examples. New examples will be added, replaced, and improved over time, so check back periodically while you're learning to use JPlates.

Use the links in the Examples section of the navigation bar on the left to look at the JPlates source files. For most examples, that's the best way to see what's really going on. Use the example title links to get back to the example descriptions on this page.

Note: All JPlates and Java sources were syntax highlighted by the JPlates HtmlGen application, which helps to point out the structure of template methods in addition to traditional syntax highlighting.


Links to Examples

The Struts Compatibility example illustrates the use of JPlates as an alternative to JSP in a simple Struts-based MVC web application. JPlates provides extensive support for working with Struts forms processing, error reporting, etc.

The Using JPlates with JSP example illustrates how to use JPlates template objects to help generate output from JSPs, combining the best of both worlds.

The Composite Web Page example illustrates a simple object-oriented framework for generating families of web pages. It illustrates template component composition and customization, subclassing, inheritance, and a number of object-oriented design patterns.

The ClassInfo Web Application example illustrates a fully functional web application, built on top of the Composite Web Page example. It illustrates separation of model from view using view-objects and view-side logic. It also illustrates different ways to use auxilliary template methods to reduce complexity and to achieve better component reuse.

The XMLTrans example is a very simple example of XML transformation using JPlates. It uses XPath expressions to navigate a parsed XML document, and the use of object-adapters to encapsulate and abstract access to different parts of the document.


Struts Compatibility

The Struts Compatibility example shows how to use JPlates as an alternative to JSP in a Struts-based web application.

The example illustrates how to use the JPlates FormAdapter class to easily build Struts-compatilbe HTML forms with much less work than JSP custom tags, how to the JPlates ActionUtils class to generate error-reporting based on Struts errors, and more.


Using JPlates with JSP

This example illustrate how to use JPlates template objects from JSPs, making view development easier, and letting you combine the best of both worlds.

The example shows how to set up the JPlates runtime from a JSP, and the simplest way to create and use JPlates template objects to help generate output from a JSP.


Composite Web Page

The composite web page example shows how to use JPlates to construct a family of similar web-pages. The example consists of a simple framework of JPlates components that provide common behavior, and JPlates subclasses that extend the framework in order to implement specific pages.

The framework sets up a standard layout for pages and allows subclasses to plug in portions of pages using standard object-oriented techniques.

The main component of the framework is defined in StandardPage.jplate. That's the most complicated component in the example, and it provides much of the common behavior and constraints. SamplePage.jplate defines a subclass of StandardPage that does the real work.


ClassInfo Web Application

The ClassInfo web application example illustrates a fully functional web-application, built on top of the Composite Web Page framework, which is described above.

The ClassInfo application simply displays information about Java classes. While that might not be a very interesting thing to do, it circumvents an important problem common to example template applications, which is where to get some useful model data (i.e. business objects) to render. Rather than complicate things with database access, the example uses Class instances that are readily accessible in the Java runtime.

The links in the example output do not work on this site, since this site is not currently running a servlet-engine. The page was copied from the application running on our local server.


XMLTrans - XML Transformation using JPlates

The XMLTrans example illustrates a powerful and scalable approach to performing XML transformation using JPlates and Java together. It uses a Java class, based on the object-adapter design pattern, to provide a high-level API to represent parts of the XML document, and a JPlates class to provide a rendering. The example uses dom4j to parse the XML and to provide XPath navigation.

The main advantages of this use of Java and JPlates over XSLT for transforming XML is that it provides both a high-level object-representation of a model and a high-level object-representation of a view, where XML by itself provides neither model nor view. The model side, implemented entirely in Java, can supply meaning and behavior to encapsulated data from the XML document. The view side, implemented using JPlates, maintains the necessary separation of view from model, and supports a more scalable solution through loose coupling and separation of concern.