Step 1: Take a look at the examples

Your first step with Apache MyFaces should be to have a look at our examples application. In the following links (kindly hosted by Irian Solutions GmbH) you will find demo applications running with MyFaces.

You can deploy the examples application for yourself. All you need to do to get up and running is to follow the steps below!:

Step 2: Deploy MyFaces Tomahawk example application.

The most simple example you can try is the ones bundled with tomahawk, which at the begining of MyFaces project was the example application bundled with MyFaces Core.

What you need for the Examples Application

  • A web server like Apache Tomcat. The example shown runs on 5.x, 6.x or 7.x, but note JSF 1.2 and later versions requires tomcat 6.x or upper. Download it from here.
  • Go to Tomahawk download page and download the webapps assembly (tomahawk-examples-X.X.X.zip or tomahawk-examples-X.X.X.tgz)

Installing and Running the Examples

  • Unpack the MyFaces examples archive tomahawk-examples.X.X.X.zip (or tomahawk-examples-X.X.X.tgz) to a directory of your choice.
  • Remove any previous MyFaces webapps from your Tomcat installation and clean up your Tomcat work dir. Also make sure that there is no jsf-api.jar or jsf-impl.jar (i.e. Suns API and implementation) in the classpath or in one of Tomcat's lib directories (for Tomcat 5.x look on common/lib or shared/lib, in tomcat 6.x or 7.x look on /lib folder).
  • Copy the file myfaces-example-simple.war (or any of the other example war-files, myfaces-example-simple20.war for JSF 2.0 variant) to the webapps dir of your Tomcat installation directory - and check once more that there is no old myfaces-examples directory there (wink)
  • Start Tomcat, if its not already running.
  • Start your browser and enjoy it at http://localhost:8080/myfaces-example-simple20.

Using MyFaces in your own web application

Suggested step:

  • Check the myfaces wiki for information about compatibility with your servlet container.

There are three possible ways to start off with MyFaces, one (recomended) is to start using myfaces archetypes:

  • Download and Install Maven
  • Execute mvn archetype:create goal using one available archetype. For more info you can look here

The second possibility is to start from the example-app:

  • If you want to have it simple, take the tomahawk-examples-X.X.X.zip you downloaded before for looking at the examples, and extract the myfaces-examples-blank-X.X.X.war file (MyFaces binary)
  • Rename the myfaces-examples-blank-X.X.X.war file to myfaces-examples-blank-X.X.X.zip, and extract this file - you have a working directory structure for a MyFaces application at hand after this step.

The third possibility is to download the core implementation and/or tomahawk (dependent on if you want to use the RI and the tomahawk components, or only MyFaces), and start from there:

After you have downloaded the necessary packages and setup your project hierarchy, do this:

*Make sure that there is no jsf-api.jar (i.e. Suns API implementation) in the classpath or in one of your container's shared lib directories (e.g. common/lib or shared/lib for Tomcat).

  • Configure your webapp's web.xml file (see conf/web.xml for example and documentation)
  • Add the following lines to your JSPs:
xml <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>

Using the MyFaces Tomahawk in your own web application

  • If you don't use the MyFaces implementation, you will need to add the file tomahawk.jar and its dependencies (see above) to your web-app directory.
  • To be able to use the MyFaces Tomahawk add the following line to your JSPs:
xml <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%> <%@ taglib uri="http://myfaces.apache.org/wap" prefix="wap" %>

Tutorials for getting started with JSF

  • No labels