JSP was great in its time. It revolutionized the way developers generated dynamic content on the web. But as with everything, time passed and other technologies were developed that made it even easier to generate this same kind of content, and on top of that, overcame many of the limitations that were introduced with JSP.
Enter JSF. It brings a graphical development mentality, similar to Swing's, which relies on a set of reusable UI components and event-driven approach. Instead of totally breaking away from its roots, JSF 2.0 can also be developed in the same way JSP is; in fact, a JSF application is a JSP/servlets application. Typically, Web Applications are developed using the MVC design pattern. This pattern works great with JSF since, in a typical JSF application, the View is the page we write, the Model is the data we wish to show, and the Controller is the FacesServlet. Every request passes through the FacesServlet. The configuration file for the FacesServlet is faces-config.xml
.
If you wish to learn more about JSF, visit:
http://www.jcp.org/en/jsr/detail?id=314
http://www.oracle.com/technetwork/java/javaee/download-139288.html
http://www.oracle.com/technetwork/java/javaee/javaserverfaces-139869.html
We will use the sources of the previously created Java EE 6 project. If unsure how to do this, refer to Introduction to Java EE 6 using NetBeans in the Creating a new Project sub-section available in this chapter.
It is also possible to use available sources from your own Java web project.
Java DB must be installed and configured. It is necessary to have a connection to the sample database. Refer to Chapter 04, JDBC and NetBeans, to learn how to do it if unsure.
Navigate to the Projects window:
FirstJavaEE6Application
, and select Properties.After adding JavaServer Faces, NetBeans creates an index.xhtml
under the Web Pages folder.
index.xhtml
is our entry point of JSF for the time being.
Here is how to run index.xhtml
on your browser.
3.16.49.108