TweetFollow Us on Twitter

Oct 01 WebObjects

Volume Number: 17 (2001)
Issue Number: 10
Column Tag: Beginning WebObjects 5

Part 2 - The Project Builder

by Emmanuel Proulx

Overview and First Application

Opening the Project Builder

The Project Builder is the central tool for developing WebObjects applications, so this article talks about how to use this tool. The first thing you're going to do is open the Project Builder, by going to your disk, under the folder /Developer/Applications, and double-clicking on Project Builder.

Currently there's no project opened. Let's make a blank one. For now, don't try to understand the different options, as we'll cover them all later. In the menu, choose File | New Project. The dialog that pops up contains many different types of projects: WebObjects, Carbon, Cocoa, bundles, frameworks, Applet, driver, C++, and many more.

WebObjects is the development platform for the Mac OS X operating system, and it can produce many kinds of projects. This column is scoped to help you develop Web applications using Java, so for now let's concentrate on this kind of project:

Select the WebObjects Application project type and click Next.

Enter the project name and location. This column assumes the project name is Find-A-Luv, under the folder ~/projects/Find-A-Luv. (Create the ‘projects' folder under the home folder). Click on Finish.

The window that comes up next is the Project Builder, containing the project you just created:


Figure 1. Project Builder.

This window is crowded with controls, which we'll cover shortly.

Overview

The Project Viewer is an IDE (Integrated Development Environment) for the Mac OS X operating system. Its graphical user interfaces resembles a Web browser. It is in fact a file browser; it lets you see the files of the project. The left part of the Project Builder ("Groups & Files") lets you select files, organizing them in a tree-like fashion into categories. I will refer to that part as the file browser tab. The right pane lets you edit the selected file - I call it the editor. Finally, the toolbar has buttons to build and run your project.

File Browser Tab

A project is a set of files that are used by a Web application. As explained in the introduction, and as you can see in the first level of the file browser, many types of files are necessary. Here's how they are classified in the Project Builder:

  • Classes: these include all Java files - the ones associated with a Web Page (or Web Component), the ones linked to the database through the model, and the utility ones that you make yourself.
  • Web Components: this contains subfolders, one for each Web page. They in turn contain all files that constitute Web Pages, for both behavior and appearance.
  • Resources: the model file (more on these later).
  • Web Server resources: all files that should be sent to the Web Server's root folder and that are not specific to components (graphics, multimedia files, executables, etc)
  • Interfaces: Java Applets.
  • Frameworks: the WebObjects-supplied libraries used by your project.
  • Documentation: HTML files containing the documentation for this project.
  • Products: the generated files for this project, including intermediate files and the final executable.

When you expand one of the categories of the first level, you can see other categories or files you may select. When you click on anything in the file browser, you will see the file appear in the editor pane.

Items in the file browser can be clicked on, double-clicked on or dragged around, just like icons of the operating system.

WARNING: If you drag something out of the file browser pane, it will be moved out of the project. The file will no longer be available in the project. If you want to copy the file, don't use the Project Builder. Use the operating system (Finder) to access the project's folder, and then copy the file from there.

The same is true when dragging files into the file browser. The file gets added to the project.

WARNING: If you drag something into the file browser pane, by default the file will not get copied. It will only be referenced. This means if you change, move or delete the file, the project will be affected. When you want to put the file inside the project, copy it into the project's folder first, and then drag it to the proper location in the file browser.

There will be more information on file management in a future article.

Editor

The second item in this window is the Editor. It works just like any text editor, except for a few features, like colored Java syntax and automatic indentation.

  • Automatic indentation: the editor adds or removes spaces and tabulations automatically as you type. When you type an open curly brace "{", it can also add automatically a closing one "}".
  • TRICK: If you want to fix the indentation for a block of text, you can do so by following these steps: select your block of text, go to menu Format | Shift Right ((-]) or Shift Left ((-[). I use this often.
  • PREFERENCE: the automatic indentation of your text can be customized by going to menu Project Builder | Preferences, and by choosing the Text Editing category. There are many options to try out.
  • Colored Java Syntax: the editor displays the keywords, comments and content using a color scheme.
  • PREFERENCE: you can decide the colors to use by going to menu Project Builder | Preferences and by choosing the Syntax Coloring category.
  • Multi-windowed view: You can open each document in its own window, that "float" above the Project Builder. You do that by choosing the menu Navigation | Open in Separate Editor. The new window doesn't have any tabs, so it maximizes the editing area.
  • TRICK: If you want to dock the tabs out of the way, you can do so simply by clicking on the currently selected tab again. The tab slides out of the view, and the editor pane becomes larger.
  • Split-window view: You can also get two views of the same document simultaneously in the same editor pane by "splitting" the editor. You do that by clicking on the button in the navigation bar. When the editor is split, you can close one of the two halves by clicking on the corresponding button.

Toolbar

The last item of this window is the toolbar. Let's briefly describe the buttons. We'll deal with what they do in great detail subsequently.

  • Build: this compile your project, letting you see the output and errors in a special pane called the Build tab.
  • Clean: I call this the "cleanup" button. This removes all intermediate files and produced binary files. Once this operation is done, the build button can rebuild everything. The output is sent to the Build tab.
  • Run: this lets you run your application. A new pane called the Run tab comes up and displays the application's output and errors.
  • Debug: this runs the application in debug mode, enabling breakpoints. You may then use the debugging buttons to control the flow of execution. You can also use the Debug tab to view the debugger's console, the variables and the frames being watched. Breakpoints are not shown in this tab; they have their own tab on the left side, called the Breakpoints tab.
  • Stop: This button appears only when the Project Builder is busy. You can stop the compilation or the cleanup by clicking it.
  • Active Target: Lets you choose which build target you are working on. A target is a set of compilation options for the current project. The targets can be configured using the Target tab.
  • Debugging buttons: lets you control the flow of execution while running the application in debug mode. The buttons are, from left to right: pause, continue, step over method, step into method, step out of method.
  • PREFERENCES: The toolbar tailored to suite your tastes. To add, remove, move and modify the appearance of the buttons of the toolbar, go to menu Window | Customize Toolbar. You may also remove the toolbar by going to menu Window | Hide Toolbar.

Other elements of the Project Builder window are:

  • The navigation bar: this lets you select which of the opened documents you wish to see, and in what class or method the cursor should jump to. With the left and right arrows, you can go back and forward in the list of documents. See this as the "Address" box, and the "Back" and "Forward" buttons of your Web browser. One more thing, you see the icon in this bar? It displays the type of document. Moreover, when a document needs to be saved, the icon becomes gray.
  • The Find tab, which lets you find (and replace) strings in the whole project.
  • The editor can be split into multiple sections, to view two different areas of the same file. These buttons let you split and close the sections.
  • The bookmarks tab, which lists the ‘favorite' files and lines of code for later retrieval.
  • The status bar, which displays the progress and result of the last operation.

Hello World Example

The Hello World Code

Enough talking. Now is time to write you first piece of code.

Open your Project Builder, pointing to the Find-A-Luv project. In the file browser tab, expand "Classes". Then, select Main.java. In the editor, you can see that file ready to be edited.

Although this class' name is Main, it has nothing to do with Java's public static void main(String []) member function. The class Main is associated with the Web Component of the same name, and for every instance of that Web Component, a new instance of the class is created too. The good news is, the Main page is the default home page for the project. So the Main class will be instantiated automatically when a user accesses your site through the ‘front door'.

We're going to make a plain Hello World example program right in here, in the constructor of the class:

Listing 1. Main.java

Main Web component
This code sample shows where to add the line that prints "hello world". 

// Main.java: Class file for WO Component ‘Main'
// Project Find-A-Luv
//
// Created by eproulx on Wed May 16 2001
//
 
import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;
import com.webobjects.eoaccess.*;

public class Main extends WOComponent {

    public Main(WOContext context) {
        super(context);
        System.out.println("Hello World!");
    }
}

Bear in mind two things before we move on: first, you can use any classes of the standard JDK 1.3 here. That's good to know because we don't have to rely on any third-party tools and libraries to do most of the work. For example, here we printed to the Console using the System class.

Second, you must know that your development environment is emulating the Web server environment. That means if you try to use any visible objects, like AWT or Swing dialogs and frames, the user will never see them. The only person that will see even just "Hello World!" is the operator guy in the Web server room. Anything you do must be just non-interactive non-graphical pure processing code (server-side processing, or business logic). The real interaction takes place when dealing with Web Components (the Web pages).

Save your code now - menu File | Save (or (-S).

Building

You are now ready to compile your project. Go to the toolbar, and click on the button with the hammer . The Build tab comes up, as shown below:


Figure 2. The build tab.

Obviously, the build has failed for this example (look at the status bar).

Let's examine the build tab. The lower half shows the compiler output. But you shouldn't have to look there, because the upper half of the build tab displays the compilation errors. In this example, there was a syntax error in the file Main.java. Clicking on the compilation error actually opens the right file and points you to the line where the error is. This is very handy.

If there were errors when you clicked on the build button, I will trust your programmer aptitudes for fixing them now. If there are no errors after the compilation, you are ready to go to the next step.

PREFERENCE: You can customize the behavior of the build process by going to menu Project Builder | Preferences, then by selecting the Build category. One of my favorite settings is to change the "Unsaved files" option to "Always Save". This way, whenever I build my project, I don't get the annoying dialog popping up asking "Save before building?"

Running

Let's see how well your "Hello World" program works. Go to the Project Builder and click on the toolbar button with the computer monitor . This opens the Run tab, as shown next:


Figure 3. The run tab and the Console.

I like to call the run tab "the Console". It displays the runtime messages, like the ones from WebObjects itself, System.err messages and guess what else? The System.out messages.

When you run the "Hello World" example, the Console displays lots of message - don't worry about these. Three things happen when you click on the Run button:

The WebObjects server is started.

Your Web application is deployed to that server.

Your Web browser pops up, pointing to the application.

The application is not displayed right away in the browser. We are redirected to it, with a page saying "One moment please...". This is just a redirection page generated by WebObjects. Immediately after that, a blank page appears. What page is this? This is the default page for your Web application, the "Main" Web Component. Does that means an instance of the Main class was created, and that the constructor we wrote was called? Go back to the Console to check it out.

Success! The words "Hello World" are displayed.

TRICK: "Compiling and running" is a common task that you will do so often, it deserves a shortcut. You can save a lot of mouse clicks by typing (-R.

You can now close the Web browser if you want. To stop the server, go back to the Console again, and click on the stop button . This will bring you back to the build tab.

Getting Help

When it comes to getting help with WebObjects, you have many choices. Often, any one source of information will do the trick, but usually one source is always better then the others for finding the specific information you're looking for. It's like wanting to listen to music and owning tons of CDs. You could pick up any one, but you have your favorite ones depending on the mood you're in right now.

Let's take a good look at each of these sources of information and check out what they do best.

Project Builder Help Menu

This contains these items:

  • Project Builder Help: this contains help on the Project Builder itself, and how to use it. It has tutorials for most of the features of the tool.
  • Developer Center, Developer Tools Help, Cocoa Help, Carbon Help: these items will get you going on using all the development libraries and tools for Mac OS X.
  • Release Notes: the latest news about the Project Builder at the time of shipping.

The help topics appear in the Mac OS X Help Viewer program, except for the release notes, which appear inside the Project Builder editor.

For API, you must know the name of the class or method you wish to look up.

WebObjects Builder Help

We'll see the WebObjects Builder in a coming article, but I wanted to introduce its Help menu right away because I prefer using it instead of the Project Builder Help menu. It contains way more material, and it brings up the Web browser right away. Invoke it from within the WebObjects Builder by going to menu Help | Help Topics or by pressing F1.

Also, the WebObjects Builder help page contains an item called "Updated Docs at Apple", that brings you the exact same help contents but with all the fixes and updates that Apple introduced over time. Be sure to bookmark that page!

Lastly, it contains a link to Apple's Search Engine when clicking on the item "WEB SITE SEARCH". Note that you have to specify what you are searching for (in the subject field, select "WebObjects Documentation").

Oh and there's also the WebObjects Builder's "tip of the day" dialog that shows up every time you start it. I'll let you explore it yourself.

Java Browser

Imagine a situation where you know what class (and what package) you want to use, but you can't remember the exact syntax for a member variable or method, or even the types and order of a method's parameters. It doesn't have to be a WebObjects class; you could want to know that for any class.

You could bring up the API help documents, but instead I suggest you fire up the Java Browser. This tool lets you explore all available packages, and view the class interfaces. I use this very often.

To open the Java Browser, open the folder /Developer/Applications, and double-click on Java Browser. A window comes up, and you can now navigate through all packages and classes that are in the classpath. Most of the WebObjects-specific classes are located under the package com.apple.


Figure 4. The Java browser

Inspector attributes help

When using the Inspector (a window that floats above tools, and show you the properties of the selected object), you can sometimes see a button in the lowest part that looks like this: . When an item is selected in the Inspector, clicking on this button will bring up the related help. This help mechanism is very specific to the context, as opposed to the previous approaches.

Help on the Web

There are several sources of help available on the Internet:

 
AAPL
$97.67
Apple Inc.
+1.41
MSFT
$43.63
Microsoft Corpora
+0.89
GOOG
$511.17
Google Inc.
-13.34

MacTech Search:
Community Search:

Software Updates via MacUpdate

Coda 2.5 - One-window Web development su...
Coda is a powerful Web editor that puts everything in one place. An editor. Terminal. CSS. Files. With Coda 2, we went beyond expectations. With loads of new, much-requested features, a few... Read more
Arq 4.6.1 - Online backup to Google Driv...
Arq is super-easy online backup for the Mac. Back up to your own Google Drive storage (15GB free storage), your own Amazon Glacier ($.01/GB per month storage) or S3, or any SFTP server. Arq backs up... Read more
Airfoil 4.8.10 - Send audio from any app...
Airfoil allows you to send any audio to AirPort Express units, Apple TVs, and even other Macs and PCs, all in sync! It's your audio - everywhere. With Airfoil you can take audio from any... Read more
Apple iMovie 10.0.6 - Edit personal vide...
With an all-new design, Apple iMovie lets you enjoy your videos like never before. Browse your clips more easily, instantly share your favorite moments, and create beautiful HD movies and Hollywood-... Read more
OnyX 2.8.8 - Maintenance and optimizatio...
OnyX is a multifunctional utility for OS X. It allows you to verify the startup disk and the structure of its System files, to run miscellaneous tasks of system maintenance, to configure the hidden... Read more
Parallels Desktop 10.1 - Run Windows app...
Parallels Desktop is simply the world's bestselling, top-rated, and most trusted solution for running Windows applications on your Mac. With Parallels Desktop for Mac, you can seamlessly run both... Read more
Apple Keynote 6.5 - Apple's present...
Apple Keynote makes it simple to create and deliver beautiful presentations. Powerful tools and dazzling effects bring your ideas to life. You can work seamlessly between Mac and iOS devices. And... Read more
OmniPlan 2.3.7 - Robust project manageme...
With OmniPlan, you can create logical, manageable project plans with Gantt charts, schedules, summaries, milestones, and critical paths. Break down the tasks needed to make your project a success,... Read more
Flavours 1.1.16 - Create and apply theme...
Flavours is a Mac application that allow users to create, apply and share beautifully designed themes. Classy Give your Mac a gorgeous new look by applying delicious themes! Easy Unleash your... Read more
Duplicate Annihilator 5.1.0 - Find and d...
Duplicate Annihilator takes on the time-consuming task of comparing the images in your iPhoto library using effective algorithms to make sure that no duplicate escapes. Duplicate Annihilator detects... Read more

Latest Forum Discussions

See All

My Very Hungry Caterpillar (Education)
My Very Hungry Caterpillar 1.0.0 Device: iOS Universal Category: Education Price: $3.99, Version: 1.0.0 (iTunes) Description: Care for your very own Very Hungry Caterpillar! My Very Hungry Caterpillar will captivate you as he crawls... | Read more »
Dungeon Dick (Games)
Dungeon Dick 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Dungeon Dick is a fantasy adventure where you must discover the wicked plot to destroy the lands . 'Fling' at your foes and land... | Read more »
Here’s How the Apple Watch Could Transfo...
With the Apple Watch’s generic release date of, “early 2015” hovering on the horizon, it’s only a matter of time before gamers begin to ask “What’s in it for us?” The obvious choice would be to place entire games directly on the face of the watch,... | Read more »
Republique Episode 3: Ones & Zeroes...
Republique Episode 3: Ones & Zeroes is Available Now Posted by Rob Rich on October 17th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Loot Raiders Review
Loot Raiders Review By Campbell Bird on October 17th, 2014 Our Rating: :: PRESS BUTTON, GET LOOTUniversal App - Designed for iPhone and iPad This menu-based loot game is suitable to compel those with pretty extreme loot lust.   | Read more »
Angry Birds are Crashing Puzzle & Dr...
Angry Birds are Crashing Puzzle & Dragons Next Week Posted by Rob Rich on October 17th, 2014 [ permalink ] Next week, Puzzle & Dragons is getting a little angry. Because, you know, Angry Birds. It’s a… a pun. I thought… never mind. | Read more »
Incandescence Review
Incandescence Review By Andrew Fisher on October 17th, 2014 Our Rating: :: ALL TAPPED OUTUniversal App - Designed for iPhone and iPad Incandescence promises intense tapping action, but isn’t particularly fun.   | Read more »
Lion Pig (Games)
Lion Pig 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: "Leaving aside the biology of how a pig and a lion might meet, fall in love, and create this curious cross-breed, Lion Pig is a... | Read more »
Zero Lives (Games)
Zero Lives 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Zero Lives is a puzzle game. Simple and elegant at its core but deep and captivating the more you play. Each puzzle will challenge... | Read more »
#SUPERHYPER (Games)
#SUPERHYPER 001 Device: iOS Universal Category: Games Price: $.99, Version: 001 (iTunes) Description: "This is a game that fans of challenging minimalist arcade games, not to mention pixel art, should keep an eye on" - Touch Arcade "... | Read more »

Price Scanner via MacPrices.net

Apple Pay Available to Millions of Visa Cardh...
Visa Inc. brings secure, convenient payments to iPad Air 2 and iPad mini 3as well as iPhone 6 and 6 Plus. Starting October 20th, eligible Visa cardholders in the U.S. will be able to use Apple Pay,... Read more
Textkraft Pocket – the missing TextEdit for i...
infovole GmbH has announced the release and immediate availability of Textkraft Pocket 1.0, a professional text editor and note taking app for Apple’s iPhone. In March 2014 rumors were all about... Read more
C Spire to offer iPad Air 2 and iPad mini 3,...
C Spire on Friday announced that it will offer iPad Air 2 and iPad mini 3, both with Wi-Fi + Cellular, on its 4G+ LTE network in the coming weeks. C Spire will offer the new iPads with a range of... Read more
Belkin Announces Full Line of Keyboards and C...
Belkin International has unveiled a new lineup of keyboard cases and accessories for Apple’s newest iPads, featuring three QODE keyboards and a collection of thin, lightweight folios for both the... Read more
Verizon offers new iPad Air 2 preorders for $...
Verizon Wireless is accepting preorders for the new iPad Air 2, cellular models, for $100 off MSRP with a 2-year service agreement: - 16GB iPad Air 2 WiFi + Cellular: $529.99 - 64GB iPad Air 2 WiFi... Read more
Price drops on refurbished Mac minis, now ava...
The Apple Store has dropped prices on Apple Certified Refurbished previous-generation Mac minis, with models now available starting at $419. Apple’s one-year warranty is included with each mini, and... Read more
Apple refurbished 2014 MacBook Airs available...
The Apple Store has Apple Certified Refurbished 2014 MacBook Airs available for up to $180 off the cost of new models. An Apple one-year warranty is included with each MacBook, and shipping is free.... Read more
Refurbished 2013 MacBook Pros available for u...
The Apple Store has Apple Certified Refurbished 13″ and 15″ MacBook Pros available starting at $929. Apple’s one-year warranty is standard, and shipping is free: - 13″ 2.5GHz MacBook Pros (4GB RAM/... Read more
WaterField Designs Unveils Outback iPad Slip...
Fresh on the heels of Apple’s announcement Thursday, WaterField Designs unveils its new Outback Slip Case for the iPad Air 2 and iPad mini 3 — a custom-fitted case for the just-announced Apple iPads... Read more
Apple Introduces iPad Air 2 & iPad mini 3...
Apple on Thursday introduced iPad Air 2, slimmed down again to just 6.1 mm, and weighing less than a pound. iPad Air 2 also features an improved Retina display claimed to deliver enhanced contrast... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** The Apple Store is a retail environment like no other - uniquely focused on delivering amazing customer experiences. As an Expert, you introduce people Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As businesses discover the power of Apple computers and mobile devices, it's your job - as a Solutions Engineer - to show them how to introduce these Read more
Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
Project Manager, *Apple* Financial Services...
**Job Summary** Apple Financial Services (AFS) offers consumers, businesses and educational institutions ways to finance Apple purchases. We work with national and Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.