Sun Java System Application Server |
This sample demonstrates the use of Java Persistence APIs based on the new Java Persistence specification along with JavaServer Faces that creates a simple authentication scheme using JavaServer Faces PhaseListeners and a simple Entity bean representing a user.
If you are familiar with EJB 2.1 persistence, you will notice many changes in this example based on the new Java Persistence specification. Although this application provides the same functionality as a corresponding EJB 2.1 implementation, it is much simpler:
Additionally, JavaServer Faces can easily use JPA within its managed bean facility through resource injection, making it easier to bridge between web and EJB applications.
The application is built and deployed as a WAR file.
The web module consists of:
index.html
page. Follow these steps to see the application in action:
JavaServer Faces Welcome Page
link.
Because the user hasn't been authenticated, the PhaseListener
will direct the user to the login page.
UserManager
will use JPA to attempt to locate
the appropriate Enity based of the provided user name.
Because the example starts from scratch each time it is deployed,
an error message states that the user doesn't exist.
Create New Account
link.
Fill out the form. If any fields are left empty,
or the passwords do not match, error messages are
provided. Click the Create
button.
If everything is in order, the user is directed
back to the login page.
JavaServer Faces Welcome Page
link. The welcome
page should greet the user with their first and last name,
and the date they registered.
Follow these steps to build, deploy, and run the application.
Make sure the JavaDB database is started. If not, refer to common build instructions.
all
to build,deploy and run the project.
clean
to remove the temporary directories
like build and dist
Follow these instructions to build, deploy, and run this sample application using NetBeans IDE.
samples_install_dir/javaee5/enterprise/jsf-jpa-war
as the project.jsf-jpa-war
and select Run Project
which will build, deploy and run the project. If configured properly, the IDE will open the browser with appropriate url. Sample output is given below. All operations completed successfully run-deploy: Browsing: http://localhost:8080/jsf-jpa-war/ run-display-browser: run: BUILD SUCCESSFUL (total time: 5 seconds)Browser output
http://localhost:8080/jsf-jpa-war/ Java Server Faces Welcome Page
If you have problems when running the application, refer to troubleshooting document.
Copyright © 2006 Sun Microsystems, Inc. All rights reserved.