Enterprise web programming

Modules ENTWA (Level 6) and APSW (Level 7)

Developing JSFs in NetBeans

This brief tutorial to developing servlets in NetBeans assumes that you know:

  1. how to use NetBeans
  2. what JSF is

Setting things up

  1. You may need to create a new project (if you haven't already got one for this work). Select File | New Project...
    1. In step 1 of the wizard, select category "Java Web" and project "Web Application"
    2. In step 2, give your project a meaningful name. As far as project location is concerned, I recommend you keep all your NetBeans projects in a single folder (on your N: drive in the University; in your "My documents" tree on your own machine).
    3. In step 3, for "server" choose the latest version of Glassfish that you have available. If you don't have any Glassfish available, you need to go back and reinstall NetBeans, making sure you choose the option of installing Glassfish at the same time.
    4. In step 4, select "JavaServer Faces" only
    5. The default settings are usually fine for fields not mentioned above.
  2. NetBeans will automatically create a working web application (of the "hello world" variety) that you can run and add to.

Executing a project

  1. Selecting Run | Run Main Project (shortcut F6) will (* if not already done):
    1. compile all files that need to be compiled and copy them to appropriate locations in your web application folder *
    2. build a WAR (web archive) file containing all your application's relevant files
    3. start up a Java web server (Glassfish) *
    4. load the WAR file up to the web server
    5. start your web browser *
    6. point your web browser to the URL that is the home page of the web application, allowing you to navigate from there
  2. Selecting Debug | Debug Main Project will do all of the above but in addition run Glassfish in a mode that allows you to set debugging breakpoints in your code and to single step through your program

Creating a new facelet

  1. A new project contains a page called index.html. This page will be loaded by default when your application starts. Initially, you can either add new JSF elements to it or create another page using the JSF wizard: Select File | New File...
    1. In step 1, choose JavaServer Faces | JSF Page
    2. In step 2, choose an appropriate name and folder for the file.

Creating a new managed bean

  1. The easiest way to create a new managed bean is to use the JSF wizard. Select File | New File...
    1. In step 1 of the wizard, select category "JavaServer Faces" and file type "JSF Managed Bean".
    2. In step 2, choose an appropriate class name and an appropriate package name. A good package name is "fred.first" if your name is fred and this is your first project.
  2. NetBeans will generate the outline of the new managed bean.You will need to add properties and actions to it.
    1. To add a property, click in the body of the class and press ALT-Insert (hold down the ALT key, press Insert); choose "Add Property...". Choose an appropriate name and type. Make sure that "Generate getter and setter" is selected.
    2. To add an action, type in a method with the signature public String doSomething(), choosing an appropriate name. The last line of the body should be return "";
 

Last updated by Prof Jim Briggs of the School of Computing at the University of Portsmouth

 
The enterprise web programming modules include some material that was formerly part of the WEB1P and WEB2P units.