Getting started with Netbeans and Myfaces

This page offers a quick start if you want to try out the MyFaces component library in Netbeans 5.0. Netbeans offers some support for JSF 1.1 and it is quite easy to define the MyFaces library.

Create a new webapplication

Netbeans comes with Tomcat installed out of the box so it isn't really necessary to install the Tomcat webserver unless you want a specific version of the Tomcat webserver.

The first step you need to take is to create a new webapplication via File -> New Project, and follow the wizard :

1. Choose Project : Choose category "Web" and pick and ordinary "Web Application". Click "Next".

2. Name and Location : Choose a directory for your project, and make sure "Source Level" has the correct setting. You will usually want to use JDK 1.5 for your project so leave this checkbox unchecked.

3. Frameworks : Pick the JSF framework. The " Servlet URL mapping" determines the URL you need to use to access a JSF page. (for example http://localhost:8084/'''faces'''/firstjsfpage.jsp).

The project is now ready for use. The wizard created the faces-config.xml file for you and also an example JSF file with the name welcomeJSF.jsp.

Create a MyFaces library in Netbeans

To be able to use all the components in the MyFaces framework you need to download a lot of Java libraries. MyFaces uses some libraries from the Apache Commons project and I never had a problem when using the latest version of these libraries. The set of libraries that works is :


All "commons" libraries can be downloaded from Apache Commons download website. The Jakarta ORO library can be downloaded from ORO website.

And finally you can download the myfaces library from the MyFaces website.

Now you need to add a new library in Netbeans via "Tools -> Library Manager". Click "New Library" en enter the name "MyFaces" (or any name you would like for the library) and add the jar files mentioned via "Add JAR/Folder...".

Project configuration

1. Open the context menu of the project in Netbeans and choose "Properties". Select "Libraries" and add a reference to the "MyFaces" library you just created. Because myfaces-all.jar contains a complete JSF implementation you need to uncheck the JSF 1.1 library . In principle it should be possible to use the tomahawk.jar file in combination with the JSF 1.1 library in Netbeans but I could not get it to work.

2. Open the web.xml file (in Configuration Files) and add the following filter definitions (Click "XML" in Netbeans to see the XML view of the file) :


The filter definitions need to be placed right under the web-app element.

A simple JSF page with a MyFaces component

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri=""%>
<%@taglib prefix="h" uri=""%>
<%@taglib uri="" prefix="t"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
                <t:outputText value="Hello MyFaces!"/>

Getting_started_with_Netbeans_and_MyFaces (last edited 2009-09-20 23:01:27 by localhost)