Home » Java » Enterprise Java » NetBeans Java EE Tip #9: Create JSF Application from Database

About Josh Juneau

Josh Juneau
Josh is an application developer and technical writer. He has authored several books for Apress, primarily focusing on Java development. Most recently, he has authored Java EE 7 Recipes, Introducing Java EE 7, and Java 8 Recipes. Josh is a member of the JCP, and he is on the JSF 2.3 Expert Group.

NetBeans Java EE Tip #9: Create JSF Application from Database

Do you need to create an database front-end very quickly?  The NetBeans IDE allows one to develop a JSF application front end for a set of database tables very quickly, and with very little coding.  Now this tutorial is an oldie, but a goodie…and it is worth mentioning again for those who are not aware of it.

First, create your application.  In this case, I create a Maven Web Application by choosing “New Project”->”Maven”->”Web Application” (Figure 1).

netbeans-ee-9a

Figure 1:  Maven Web Application

Next, I provide the web application name of JsfCustomers since I’ll be making use of the CUSTOMERS sample database tables.  Once the application project is created, create a new Java package to hold the entity classes for the database.  In this case, I right-click on the project’s “Source Packages” and select “New”->”Java Package…”, and then name it org.jsf.jsfcustomers.entity  (Figure 2).

netbeans-ee-9b

Figure 2:  New Java Package

After the package is created, right-click on it and select “New”->”Entity Classes from Database”, which I’ve covered in a previous posting.  This wizard allows me to select a set of database tables from one of my connections…here I choose my sample database and select the CUSTOMER table.  After doing so, all related database tables are automatically added to the “Selected Tables” list…click next (Figure 3).

netbeans-ee-9c

Figure 3:  Create Entity Classes from Database

The next wizard page (Figure 4) allows me to select various options for generating my entity classes…I’ll leave the defaults and click “Finish”.

netbeans-ee-9d

Figure 4:  Entity Class Options

After doing so, the entity classes for my database have been generated.  Now it is time to put the icing on the cake.  Since the database entity classes are now available, I can generate the entire JavaServer Faces infrastructure with just a few clicks.  Right click on the project’s “Web Pages” folder and select “New”->”JavaServer Pages”->”JSF Pages from Entity Classes” (Figure 5).

netbeans-ee-9f

Figure 5:  Create JSF Pages from Entity Classes

Next, select all of the entity classes that have been created, and click “Next” (Figure 6).

netbeans-ee-9g

Figure 6:  Select Entity Classes

Lastly, specify options for creating your JSF classes and pages.  First, I specify a good name for my EJB session bean and JSF Controller packages.  The EJBs and controllers will be automatically generated into these locations.  Next, select the web folder where the JSF pages should be generated…leave blank for the root.  Lastly, I chose to utilize the PrimeFaces pages template to make use of PrimeFaces components.  Click next and choose the JSF configuration that has been previously registered with the IDE (Figure 7).  Lastly…click “Finish” and see the magic…the web application and all of the JavaServer Faces infrastructure is generated automatically (Figure 8).

netbeans-ee-9h

Figure 7:  JavaServer Faces Configuration

netbeans-ee-9i

Figure 8:  Completed JSF Application

Note that you may need to right-click on your project “Dependencies” module and add PrimeFaces (Figure 9).

netbeans-ee-9j

Figure 9:  Add Maven Dependency

Now build and run your application…and it is ready to use!

netbeans-ee-9k

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy

Leave a Reply

avatar

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  Subscribe  
Notify of