The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 3)

I hope Geertjan doesn't mind, but I've written Part 3 of his popular blog entry: The Best Feature of the Upcoming NetBeans IDE 5.5.

Last month, my colleague Geertjan[2] wrote a couple of pretty popular blog entries:The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 1[3]) and (Part 2[4]). It basically showcases 2 new wizards in NetBeans 5.5: Entity Classes from Database and JSF Pages from Entity Class, that when run back to back essentially create a fully functional CRUD (Create, Read, Update, Delete) application. I was curious how this would work with JBoss, so below for you I document my experiences.

Getting Started

Download[6] and install JBoss 4.0.4. During installation, be sure to select the ejb3 profile.

Step 1: Add the JBoss Server to NetBeans

Switch to the Runtime tab and right-click the Servers node to add a server.

Select JBoss Application Server 4 from the Server drop down list. Change the name to JBoss Application Server 4.0.4.

Complete the Add Server wizard.

Stop the Sun Java System Application Server if it is running (both servers use http port 8080 as their default).

Right-click the new JBoss server node and choose Start:

Step 2: Create the Project

JBoss doesn't ship any sample data with it's HSQLDB. However, there are a few system tables in place to support JMS, so to keep things as simple as possible, we'll go with one of those: JMS_USERS.

Create a New Web Application Project named JMSUserEditor. Be sure to select JBoss as the Server (Note, although JBoss supports components of the Java EE 5 specification, notably EJB 3.0, JBoss 4.0.4 is a J2EE 1.4 compliant application server. Therefore, Java EE 5 is not an available option for J2EE Version.). Also, uncheck the option to Set Source Level to 1.4, as we will be using annotations which require Java 5.0.

On Step 3 of the wizard, Frameworks, be sure to select Java Server Faces and click Finish.

Step 3: Prepare the Project for JBoss

There are a couple of additional steps we need to take in order for the project to run successfully on JBoss. Issues have been filed and these steps will not be necessary with the 5.5 final release.

Remove the JSF and JSTL libraries from the project (Issue 76733[7]). Open the Project Properties, select the Libraries node and Remove the JSF and JSTL libraries from the project.

Add the MyFaces Context Listener to web.xml (Issue 74392[8]). Open the web.xml and expand the Web Application Listeners node. Click Add and add the org.apache.myfaces.webapp.StartupServletContextListener class.

Press F6 to test run the project. If you can load the page that says Java Server Faces, your project is set up correctly:

Step 4: Setup the Database

Follow the steps from this blog entry[9] to set up HSQLDB to run in server mode. This will allow the wizards in the next step to connect to the database. It will also allow you to use NetBeans' database explorer tools to browse the data.

Step 5: Create the Persistence Unit

Press Ctrl+N to create a new file and select the Persistence Category > Persistence Unit.

Set the Persistence Unit Name to default and click Finish.

Press Alt+Shift+Right to open the XML view and replace the persistence unit with the following: