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:
- 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.
Note: The users table was added by me when I followed the tutorial mentioned at start.
- 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!!
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.
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!!
Though he tried doing it in NetBeans 6.1 Beta and got some bugs.