Table of Contents Previous Section

Implement Application.java

In the previous section, you implemented a class named RegistrationManager, which maintains the list of registrants. You need to create an instance of RegistrationManager. Create the instance in Application.java.

  1. In WebObjects Builder, open the Registration application window.

  2. Click the Application tab.

  3. Choose Tools Script Scripts to open the Script window.

    Instead of displaying a script, this window displays the Application.java file. Application.java defines an class named Application to be a subclass of WebApplication, and it shows the main method that WebObjects Builder provided for you.

  4. Implement Application.java as shown below. (Don't change the main method.)
    	import next.util.*;
    	import next.wo.*;
    
    	public class Application extends WebApplication {
    
    		private protected RegistrationManager manager;
    
    		public static void main (String args[]) {
    			ProcessInfo.setCommandLineArguments(args);
    			Application application = new Application();
    			application.run();
    		}
    
    		public Application() {
    			super();
    			manager = new RegistrationManager();
    		}
    
    		public RegistrationManager manager() {
    			return manager;
    		}
    
    	}
    
In addition to declaring the RegistrationManager instance variable and initializing it in a constructor, you also need to create an accessor method named manager. Components will use the manager method to access the RegistrationManager object. Because you're writing a compiled application, you need to write the manager method yourself. If you were using WebScript, manager would be implicitly implemented when you declared the manager instance variable.

You can edit the file Application.java in Project Builder, but you must be careful if you do. WebObjects Builder does not detect if files have been edited externally. If you make a change in Application.java using Project Builder and then edit it in WebObjects Builder, WebObjects Builder will overwrite the previous changes. If you want to edit files externally, make sure that you only have the file open in one application at a time, and always close the file as you move from one application to the next. To avoid the problem entirely, it's a good rule of thumb to edit custom objects in Project Builder and edit component logic in WebObjects Builder.

Table of Contents Next Section