Differences between revisions 4 and 5
Revision 4 as of 2008-02-20 14:59:13
Size: 4652
Editor: cg0def
Comment: updated url address for the Apache Commons site.
Revision 5 as of 2009-09-20 23:01:27
Size: 4659
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
This page offers a quick start if you want to try out the MyFaces component library in [http://www.netbeans.org Netbeans 5.0]. Netbeans offers some support for JSF 1.1 and it is quite easy to define the MyFaces library. This page offers a quick start if you want to try out the MyFaces component library in [[http://www.netbeans.org|Netbeans 5.0]]. Netbeans offers some support for JSF 1.1 and it is quite easy to define the MyFaces library.
Line 15: Line 15:
1. '''''Choose Project''''' : Choose category "Web" and pick and ordinary "Web Application". Click "'''Next'''".[[BR]] 1. '''''Choose Project''''' : Choose category "Web" and pick and ordinary "Web Application". Click "'''Next'''".<<BR>>
Line 17: Line 17:
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.[[BR]] 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.<<BR>>
Line 28: Line 28:
commons-lang-2.1.jar[[BR]]
commons-beanutils.jar[[BR]]
commons-codec-1.3.jar[[BR]]
commons-collections-3.1.jar[[BR]]
commons-digester-1.7.jar[[BR]]
commons-el.jar[[BR]]

commons-fileupload-1.1.jar[[BR]]
commons-validator-1.2.0.jar[[BR]]
commons-io-1.1.jar[[BR]]

jakarta-oro-2.0.8.jar[[BR]]
myfaces-all.jar[[BR]]
commons-lang-2.1.jar<<BR>>
commons-beanutils.jar<<BR>>
commons-codec-1.3.jar<<BR>>
commons-collections-3.1.jar<<BR>>
commons-digester-1.7.jar<<BR>>
commons-el.jar<<BR>>

commons-fileupload-1.1.jar<<BR>>
commons-validator-1.2.0.jar<<BR>>
commons-io-1.1.jar<<BR>>

jakarta-oro-2.0.8.jar<<BR>>
myfaces-all.jar<<BR>>
Line 40: Line 40:
All "'''commons'''" libraries can be downloaded from [http://commons.apache.org/downloads/index.html Apache Commons download website]. The '''Jakarta ORO''' library can be downloaded from [http://jakarta.apache.org/site/downloads/downloads_oro.cgi ORO website]. All "'''commons'''" libraries can be downloaded from [[http://commons.apache.org/downloads/index.html|Apache Commons download website]]. The '''Jakarta ORO''' library can be downloaded from [[http://jakarta.apache.org/site/downloads/downloads_oro.cgi|ORO website]].
Line 42: Line 42:
And finally you can download the '''myfaces''' library from the [http://myfaces.apache.org/download.html  MyFaces website]. And finally you can download the '''myfaces''' library from the [[http://myfaces.apache.org/download.html|MyFaces website]].

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 :

commons-lang-2.1.jar
commons-beanutils.jar
commons-codec-1.3.jar
commons-collections-3.1.jar
commons-digester-1.7.jar
commons-el.jar
commons-fileupload-1.1.jar
commons-validator-1.2.0.jar
commons-io-1.1.jar
jakarta-oro-2.0.8.jar
myfaces-all.jar

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) :

    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.component.html.util.ExtensionsFilter</filter-class>
        <init-param>
            <param-name>maxFileSize</param-name>
            <param-value>20m</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <url-pattern>/faces/*</url-pattern>
    </filter-mapping>

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="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <f:view>
            <h:form>
                <t:outputText value="Hello MyFaces!"/>
            </h:form>
        </f:view>
    </body>
</html>

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