Deploying Custom JSF Components – and using them in new JSF Applications

In several previous posts – and some articles yet to be published – I discuss the development of new JSF Components. Of course the true potential of such components can only be realized if they can be packaged and distributed and integrated in an IDE and new JSF application in a very simple way. This articles demonstrates how two simple custom JSF components – a Validator and a UIComponent – can be packaged in a JAR file with supporting configuration files and subsequently be distributed to be used in other applications.

The jar-file is available for download at the end of this article. You can download it and create wonderful new applications with the two custom JSF components: helloworld and greaterThanValidator:

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF runapp 

....
 

Packaging the custom components in a distributable bundle (JAR file)

The custom components are developed in several steps and through several moving parts:

  • The class that extends UIComponentBase (for the custom UIComponent HelloWorld) and the class that implements the Validator Interface (for the custom GreaterThanValidator)
  • The tag class that supports the specific JSP tag for the custom component
  • The entry in the TLD (the Tag Library Description)
  • The registration in the faces-config.xml file

Each of the above constituent parts has to be part of the distribution of the custom components. This distribution is a JAR file. The JAR should contain a META-INF directory with in it the tld file (with the tag-descriptions) and the faces-config.xml file (with the component and validator registrations). The class files are in the directory structure defined by the package structure with its root in the root of the jar file. Our jar-file has the following structure and contents (again for the helloworld component and the GreaterThanValidator):

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF jar

This is all it takes. We now have a jar-file we can send to all our friends and loved ones!

Importing the custom components in a New JSF Application

To make use of the custom components that are packaged in the AMISJSF.jar file, we have to go through some simple steps – I will demonstrate them in Oracle JDeveloper; however, the steps should be quite similar with other IDEs: 

1. Copy the jar-file to the WEB-INF\lib directory of the application 

2. Create a new library for this jar file

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF editLibrary

3. Add the new Library to the ViewController-project 

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF projectLibraries

4. Add the AMISJSF tag library to the ViewController project 

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF taglib

5. Create a new JSF page in the application:

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF createNewPage

6. Select the Tag Libraries to use in the page – out of the selection that was added to the project:

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF newPageUseTaglib

Now all tags in the AMISJSF tag library are available in the JDeveloper JSF Component Palette and can be dragged and dropped to our new JSF page:

Deploying Custom JSF Components - and using them in new JSF Applications useCustomJSF palette

Resources

Earlier installments in this series on JSF development: How to develop a Custom JSF Validator and How to enable Client Side Validation in Custom JSF Validators

The jar-file with the two custom components AMISJSF.jar

The Complete Reference – Java Server Faces by Chris Schalk and Ed Burns (ISBN 0072262400) – a very good introduction, overview and reference for most things related to JSF

One Response

  1. mauro January 6, 2010