JSFCrudGeneratorIn6.1

Conrtibuted by: Jay Mahadeokar.

Contents


Introduction:

NetBeans 6.1 comes up with new JSF Crud generator. Lets try and explore..

I must confess I have no prior knowledge of JSF and learned it through the tutorial, “Using Java Persistance API within a Visual Web JSF Application”. So if any of concepts are wrongly presented here please excuse me.

In the above tutorial we learn first to create a table in Database and then use NetBeans 6.0 JSF functionality to create a page that will simply display table contents. The tutorial thus guides us in making Hello World example for Web Application through NetBeans.

If you go through the tutorial you will realize the steps and coding that is required to simply display the data from one table.

Here we will explore the new JSF crud generator feature in NetBeans 6.1 and see for ourselves how easily we can create a database application using its features.

Three steps in creating the Application:

1. Setting up the web project:

1. We will use the sample derby database that comes up with NetBeans for our application. (jdbc:derby://localhost:1527/sample) To connect to database: Goto services tab >> right click on app on App >> connect. File:jsf1_JSFCrudGeneratorIn6.1.JPG

2. If you expand the tables node, following tables will bhe seen:

Note: The users table was added by me when I followed the tutorial mentioned at start. File:jsf2_JSFCrudGeneratorIn6.1.JPG

 3. Create a new Web application. In the frameworks window click on Visual Web Server faces.

File:jsf3_JSFCrudGeneratorIn6.1.JPG

Now the project has been set up.

2. Creating the Entity classes from database:

1. Right click project >> New >> Entity Classes from database. File:jsf4_JSFCrudGeneratorIn6.1.JPG

2. In Data Source select the JDBC / sample File:jsf5_JSFCrudGeneratorIn6.1.JPG

3. The data tables will be shown. Say add all to create classes for all tables. File:jsf6_JSFCrudGeneratorIn6.1.JPG

4. Click on Create Persistance Unit option. File:jsf7_JSFCrudGeneratorIn6.1.JPG

5. Following dialog will be shown. Click create. File:jsf8_JSFCrudGeneratorIn6.1.JPG

6. Click finish. You will see following classes created in Source Package > App node File:jsf9_JSFCrudGeneratorIn6.1.JPG


3. Creating JSF pages from entity classes:

1. Now goto WebPages > Resources and right clict >> New >> JSF pages from entity classes. File:jsf10_JSFCrudGeneratorIn6.1.JPG


2. All entity classes will be shown. Say Add all. File:jsf11_JSFCrudGeneratorIn6.1.JPG


3. Click next. The Wizard will ask you to specify the JSF Pages folder. Browse and specify it properly. Thats where your page will get generated. In my case it was WebApplication1\WebPages\Resources\ File:jsf14_JSFCrudGeneratorIn6.1.JPG

4. A new file WelcomeJSF.jsp will be added to the directory. Open it and try to understand what is actually happening. Also explore the new files created in the Sources folder. You will realize the amount of coding the generator does for us.

5. Now just Right Click WelcomeJSF.jsp and say Run File. That’s it!!


Output:

A new web page will appear as follows: File:jsf12_JSFCrudGeneratorIn6.1.JPG

Click on any of the links, say Product code items. You will see following page: File:jsf13_JSFCrudGeneratorIn6.1.JPG

Thus options for selection, Editing, Deleting, Adding new data all are provided for us. Easily navigation links are also provided.

Conclusion:

Thanks to the new JSF crud generator in NetBeans IDE 6.1 we are just clicks away from representing our whole database through robust and well designed web pages. So if you have a database ready and want to create a web application representing it, think of NetBeans 6,1 and JSF Generator will be at your service.

Again.. Hats off to NetBeans!!

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo