MyFaces Tomahawk

Tomahawk has been part of the Apache MyFaces project from the very beginning. Its main goal is to implement a larger set of components than the rather minimal set that is defined in the JSF specification. Tomahawk contains both extended versions of standard JSF components and components that are not defined at all in the standard. Some examples of components that are added by Tomahawk are:

Tomahawk also features some custom validators that make it easy to validate, for instance, credit card numbers and email addresses. There are three variants of Tomahawk, as follows:

Getting started with Tomahawk

To use the Tomahawk component set, we first have to do some set up. The following steps have to be taken:

  1. Download Tomahawk and add it to our project
  2. Make some settings in the web.xml file

  3. Add some extra libraries to resolve a few dependencies

The following subsections will focus on each of these tasks.

Downloading Tomahawk

Tomahawk comes in three flavors:

Each of those versions can be downloaded from the download page of the Tomahawk project.

Configuring web.xml

Tomahawk uses a special Extensions Filter. This filter is used to serve common resources such as images and JavaScript files. These resources are needed by some of the components, and are provided in the Tomahawk JAR file. The Extensions Filter can provide resources transparently; it doesn’t matter if the resources are located as separate files within the project or in a JAR file in the classpath. We have to add some lines to our web.xml file to make this extensions filter work. First, we have to define the filter itself:


The filter-name can be anything, but it’s a good idea to choose a descriptive name. The filter-class is the fully-classified name of the Filter implementation that is provided by Tomahawk. This class can be found in the Tomahawk JAR. The ExtensionsFilter is also used to handle file uploads for the <t:inputFileUpload> component. Therefore, we have to set the maximum file size for uploads here. Any file size can be set, and the following suffixes can be used:

Now that the filter is defined, we have to add at least one filter mapping to make it work. Tomahawk uses two filter mappings. The first filter mapping looks like this:

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

The filter-name value refers to the name that we defined in the filter definition. The servlet-name refers to the name that we gave to our Faces Servlet. If you gave your Faces Servlet another name, make sure that you use that name here. This mapping will cause all pages that are handled by the Faces Servlet to pass the through the Extensions Filter. This enables the Extensions Filter to scan each page for links to resources, and then change those links so they point to the Extensions Filter.

In the second filter mapping, we need to map a URL prefix to the Extensions Filter. This will cause all requests that start with this pattern to be routed directly to the Extensions Filter. The Extensions Filter can then serve up the requested resource. This filter mapping looks like this:


Again, the filter-name should match the name defined in the filter definition. The url-pattern can be anything, but it should start with the pattern that is used for the Faces Servlet (/faces/* in this example). It is also a good idea to have some relation between the name of the filter and the second part or the URL pattern. Now we’re ready to go!

Resolving dependencies

Various Tomahawk components depend on one or more external libraries, which are not distributed within the Tomahawk package. Of course, you don’t need to download the dependencies yourself if you’re using Maven. But if you're not, you can refer to the following table to resolve the dependencies manually:

Library Version

Needed by

Apache Batik 1.6


Apache Commons IO 1.3.2


Apache Commons Validator 1.3.1

Tomahawk validator components

The listed versions apply to Tomahawk 1.1.9. You should understand that different versions of Tomahawk may depend on different versions of the listed libraries, or even on other libraries.

Drafts/Site/Tomahawk (last edited 2011-03-18 13:51:29 by a82-95-155-119)