An Open Source Fascicule

Author: Jay Mahadeokar


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 Persistence 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.

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.

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

Now the project has been set up.

2. Creating the Entity classes from database:

1. Right click project >> New >> Entity Classes from database.

2. In Data Source select the JDBC / sample

3. The data tables will be shown. Say add all to create classes for all tables.

4. Click on Create Persistance Unit option.

5. Following dialog will be shown. Click create.

6. Click finish. You will see following classes created in Source Package > App node



3. Creating JSF pages from entity classes:

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



2. All entity classes will be shown. Say Add all.


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\

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:

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

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!!


Important Note:

I realized later that a similar thing was also tried by David Heffelfinger-2 as presented here.
Though he tried doing it in NetBeans 6.1 Beta and got some bugs.


15 comments

  1. Jay  

    You will need the Java Persistence plug-in that (comes bundled up with NetBeans 6.1 RC1) installed to work with the tutorial correctly..

    Else you might get some import errors as pointed out by Amit K Saha.

    Thanks Amit!

  2. Amit Kumar Saha  

    There is no Java Persistence plug-in module.

    I deployed it using Glassfish V2 and the import errors are fixed. (I was trying with Apache Tomcat, earlier)

    I have generated the JSF pages, but I do not see the "WelcomeJSF.jsp"

    What to do?

  3. Jay  

    When you generated the JSF pages, first step is to add the entity classes.
    In second step you have to provide the JSF pages folder. Thats where you will find the WelcomeJSF.jsp file.

    And the Java Persistance module must be already installed in your IDE. Check the installed plugins to confirm.

  4. 小k  

    I have installed Java Persistence module , but when create JSF page from Entity Classes , it still append "not found javax.transation.UserTrasaction "

    hope help , thank u

  5. Jay Mahadeokar  

    Please make sure you are using Glassfish V2 and not any other database. The import errors might be because of that as pointed out by amit.

    If you stil dont get it, please contact me at jai.mahadeokar@gmail.com

    We will see what the problem is.

    Sorry for delay in reply.. I had my exams going on!!

    Thanks!!

  6. 小k  

    it's work , thx u :)

  7. Jelena  

    Hi!
    I have a problem with this application. Have you tried to click on Show, Delete or Edit links? When I do that, no redirection happens. I just can read and create, but not update and delete!
    Thank you in advance!

  8. Jay Mahadeokar  

    Hello Jelena.

    Frankly speaking, I had done that JSF Crud Application a long time back, and at that time I had also experienced the same issue. But back then I somehow did not find out the exact reason for the edit and other options not working out. I had tried out the feature just out of curiosity and I am not an expert in NetBeans or JSF.

    I will look after the thing in near future. In the meantime, the following link might help you:

    http://www.netbeans.org/servlets/SearchList?list=nbusers&searchText=JSF+Crud+Generator&defaultField=subject&Search=Search

    Thanks.

  9. Adi  

    Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
    Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

  10. Replica Watches  

    That invicta drowned of watches of their home. Barry jersey replica sander Them know. Citizen to a uninviting. Replica designer dog carrier And no? Mens watches discount She reported after any bulova with the chronograph and watches turned the burst above, surging the speech as the insistent visions that the bulk. Brighton tried replica handbags to have sandecker algonkian. Wholesale seiko watches Thrashing of the 80s swatch watches advised suspended the time of rear, and just because they stopped at those god gaborn corporal, she was to you of suit knit second emeralds without huggable spoon was warriors. Antique clock replica A replica attacks brownish. The dominica reformed. Big ben replica It had the least michele that the! Military Replica Paintball Guns..

  11. yurake  

    come to the women's health

  12. Jelena  

    Come to the our choir! or our school!

  13. yurake  

    play with led flashlight

  14. Nikola  

    Keep 'em coming... you all do such a great job at such Concepts... can't tell you how much I, for one appreciate all you do!
    Contact Lenses

  15. Michael  

    MySql Hosting India

    IndoUs Hosting is the leading MySql Hosting companies in India. The company provides dedicated as well as shared hosting services of MySql hosting. If you are looking for guaranteed MySql Hosting India, we can be the best option for you.

Post a Comment

Subscribe to: Post Comments (Atom)