Search This Blog

Wednesday, September 15, 2010

JSF 2.0 - "Hello World" in NetBeans (with *.xhtml pages)

Requirements:
  • installed Java (description here)
  • installed and configured NetBeans (description here)
  • installed and configured Tomcat for the NetBeans (description here)
You will learn:
  • how to create "Hello World" application in JSF 2.0 using NetBeans
Note 1: The following post and example show classic JSF 2.0 application with a view technology as .xhtml pages. I do not use any additional libraries and extensions for the standard JSF libraries. JSF implementation used comes from Sun.

Note 2: I use standard capabilities of IDE platform to generate the project, without those thousands automated plugins which do everything for the user. Sometimes configuration and usage of a plugin is a "pain in the ..." - in my opinion it is worth to know how to deal with a standard set of tools, and after that there is always a time to faciliate our life ;-)

In a previous post I showed how to create a sample JSF 1.2 application using NetBeans. Creating JSF 2.0 application under NetBeans is almost the same as creating JSF 1.2 application - the main difference is just selecting JSF 2.0 version instead of 1.2.
I will show how to create JSF 2.0 sample application similar to JSF 1.2 application.

Step 1: creating and configuring web application.

Now we have to define project name and its location:

After pressing "Next" we have to configure target runtime and context name:

Press "Next" in order to go to the JSF settings screen. Here we have to select JSF 2.0 version:

Step 2: project is configured. This is what NetBeans generated for us:

Just like for version 1.2, project contains all requires libraries and is ready to be deployed on the server.

Step 3: creating application.

This will be the same application as for version 1.2 with some differences coming from JSF 2.0:

- pages extenstion will be .xhtml instead of .jsp
- we use annotations in backing beans
- there will be no faces-config.xml file (now)

Everything should look like this:

Step 4: deploying on server and running.

This step is exactly the same as step 4 from previous post about sample JSF 1.2 application. We also don't have to start the browser manually to see the application. Browser will be started automatically with proper URL pointing to our application.

What next? This simple working project can be used as a base for further learning about JSF. For example we can change the view technology from .jsp to facelets. We can add libraries which extend our standard tags by adding tags with ajax support, i.e RichFaces.

No comments:

Post a Comment