This post is a step-by-step guide to setting up NetBeans for JSF (Java Server Faces) web development. It shows how to configure NetBeans for auto-completion of JSF tags and the meta-data in faces-config.xml.
The following will be required.
- A DTD for faces-config.xml
- A JSF implementation
- NetBeans 4.0
Setting Up the Project
Create a new web project by selecting File > New Project… > Web > Web Application.
Creating a JSF Library
Create a library to contain JSF classes, tag libraries, etc. by selecting Tools > Library Manager… In the Library Manager, click on New Library, specify a name, and select Class Libraries as the type.
Select the library that you just created from the list and click on Add Jar/Folder; add the JAR files for the JSF implementation and required tag libraries.
Registering the Library in the Project
Right-click on the project and select Properties; select Compiling Sources; click on Add Library; and select the library that has just been created.
You also need to register JSTL in the project.
In order to include the files required for JSF in the final package, click on Packaging Project and add the libraries as in the previous step.
The JAR and other required files are now registered on the classpath for this project.
Create a new folder dtds under WEB-INF by right-clicking on it, selecting New > Folder, and typing “dtds”.
Download the DTD file for Sun’s reference implementation of JSF and extract it in the dtds folder.
Tip: Use a file manager to do this. Files cannot be pasted directly into NetBeans.
Once this is done, create faces-config.xml by right-clicking on WEB-INF and selecing New > XML document, and typing “faces-config”.
Replace the content of faces-config.xml with the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
Because we have copied the DTD for this XML file in the dtds folder, we specify this, as shown in the code extract.
The content can now be added, using the auto-completion if required.
Writing JSP Files
Right-click on WEB-INF and create a JSP file. Add the taglib directives at the beginning of the file. This will allow the editor to use auto-completion for JSF tags.
Note: The JSP editor says “JSP completion” instead of “JSF completion.”
This tutorial shows how to work around the lack of native support for JSF in NetBeans.
Technorati Tags: NetBeans