Although NetBeans 5.5 beta has no direct support for Facelets (yet?), you can successfully develop JSF Facelets applications with it, and take advantage of NetBeans' Java EE 5 platform support and other cool things.
In this this tutorial I will create a new Web Application in NetBeans 5.5 beta, based on the NumberGuess example included in the Facelets distribution. This tutorial assumes that you have basic JSF, Facelets and NetBeans knowledge. Before starting make sure you have the following in place:
- Java EE 5 SDK, Sun Java System Application Server PE 9 or GlassFish installed.
- NetBeans 5.5 (beta) installed.
- The installed Java EE 5 Server registered in NetBeans.
- Unpackaged distribution of Facelets (in this tutorial I used Facelets 1.1.4).
The NumberGuess example is a simple application consisting of a couple of JSF pages and navigation rules and a single JSF managed bean. Follow the steps below to set up the NumberGuess project in NetBeans and deploy and run it from within the IDE.
- Register the Facelets library in NetBeans (Tools --> Library Manager). Create a New Library containing the jsf-facelets.jar from the Facelets distribution.
- Create a new Web Application project. Choose as Project Name numberguess (make sure the context path is also set to numberguess) and select the Java EE 5 server you installed as Server. Select Java Server Faces in the Frameworks step. Click Finish to create the project.
- NetBeans will automatically create an index.jsp and welcomeJSF.jsp. Delete both files as we will not be using JSP pages, but xhtml formatted JSF pages.
- Add the Facelets library to your project (Project Properties --> Libraries --> Add Library).
- Copy the tutorial directory (containing the managed bean class) from \facelets-1.1.4\demo\numberguess\src\ to your projects \src\java\ directory. NetBeans will refresh your project content automatically.
- Also copy all files from \facelets-1.1.4\demo\numberguess\web\ to your projects \web\ directory. Do NOT copy the \WEB-INF\ directory.
- Open your projects web.xml and add the folowing:
Next, change the the Faces Servlet url pattern from /faces/* to *.jsf (next time you can do this when creating the project).
Also completely remove the welcome file list configuration which was pointing to the deleted index.jsp file.
- Open your projects faces-config.xml and add the folowing:
<!-- our NumberBean we created before -->
<!-- going from guess.xhtml to response.xhtml -->
<!-- going from response.xhtml to guess.xhtml -->
The most important part is to configure the FaceletViewHandler to use Facelets as view technology. The other parts are just 'normal' JSF managed beans and navigation rules which you would also need without using Facelets.
- Deploy and Run your project.