Skip to main content

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

Posted by bleonard on May 23, 2006 at 7:54 AM PDT

Last month, my colleague Geertjan wrote a couple of pretty popular blog entries:The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 1) and (Part 2). 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 and install the NetBeans 5.5 Beta.
  • Download and install JBoss 4.0.4. During installation, be sure to select the ejb3 profile.
Step 1: Add the JBoss Server to NetBeans
  1. Switch to the Runtime tab and right-click the Servers node to add a server.






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






  3. Complete the Add Server wizard.
  4. Stop the Sun Java System Application Server if it is running (both servers use http port 8080 as their default).
  5. 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.

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






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

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






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




  3. 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 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
  1. Press Ctrl+N to create a new file and select the Persistence Category > Persistence Unit.
  2. Set the Persistence Unit Name to default and click Finish.
  3. Press Alt+Shift+Right to open the XML view and replace the persistence unit with the following:
  <persistence-unit name="default">
    <jta-data-source>java:/DefaultDS</jta-data-source>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value=""/>
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
    </properties>
  </persistence-unit>
 
Step 6: Create the Entity Classes
  1. Press Ctrl+N to create a new file and select the Persistence Category > Entity Class from Database File Type.
  2. Select the Database Connection jdbc:hsqldb:hsql://localhost:1701 [sa on PUBLIC] and the JMS_USERS table.







    Click Next.



  3. Set the Package to entity and click Finish.
Step 7: Create the JSF Pages
  1. Press Ctrl+N to create a new file and select the Persistence Category > JSF Pages from Entity Class File Type.
  2. Add the JmsUsers Entity Class to the Selected Entity Classes. Click Next.
  3. Set the Package to controller and click Finish.
Step 8: Run Your Application
  1. Press F6 to run the application.
Related Topics >>