TweetFollow Us on Twitter

Nov 01 WebObjects

Volume Number: 17 (2001)
Issue Number: 11
Column Tag: Beginning WebObjects 5 Web Applications

Part 3 - Project Builder

by Emmanuel Proulx

Project Management & Debugging

Managing the Project

About Targets

Targets are sets of configuration options. Each target represents an area of the system, which should be packaged together. By default, a project has 3 targets:

  • The project itself (Find-A-Luv), contains the two other targets:
  • Application Server: contains the files that should remain on the server (basically all files that you create, except Applets)
  • Web Server: contains the Applets that should be downloaded by the client (this target should really be called "Applet")

When compiling, always select the project target. When adding files, select the Application Server target, and then switch back to the project target afterwards.

If you add the files under the wrong target, simply un-check the file under that target (in the file browser, under the first column: the one with the bull's eye), switch to the good target, and check the file again.

Creating files

The default project comes with a handful of files; a single Web Component, and a few classes. You can create new file by going to menu File | New File, then by selecting the type of the file you want. Again, many types of files can be created: a simple empty file, a Java class, Web components, Cocoa (Java, Objective-C), Carbon (C++).

Many other types of files are available, but the ones that interest us for now are:

  • Component: This is a Web page of our application. It is not just one file; it is a set of dependant files describing the appearance and behavior of the page.
  • Java Class: This is a "utility" or "helper" class, one that is not associated with a Web component or WebObjects' frameworks.

Let's make such a helper class. We'll introduce a new Value Object class that's only goal is to store data for our Find-A-Luv example. In the file browser of the Project Builder, select the "Classes" group. In the target selection box, choose "Application Server". Go to menu File | New File. Select the "Java Class" and click on Next. Now type in the filename APerson.java. Click Finish.

NOTE: Before you choose the menu File | New File, be sure you selected the right

  • group or folder in the file browser
  • target (usually you want to add the file inside target "Application Server")

The selected group/folder and target will end up containing the file you create.

Now switch back the selected target to "Find-A-Luv". Open Person.java again and enter the following code:

Listing 2. APerson.java

This class is just a small Value Object that can contain a single person's information: name, sex, 
email address, smoking or not, and description. 

//
// APerson.java
// Project Find-A-Luv-b3
//
// Created by eproulx on Sun Sep 09 2001
//

import com.webobjects.foundation.*;
import com.webobjects.appserver.*;
import com.webobjects.eocontrol.*;

public class APerson extends Object {
 protected String name;
 protected String sex;
 protected String email;
 protected Boolean smoking;
 protected String descrip;
 
 public String toString() {
  return "Hi, my name is " + name + ". I am a " + sex + 
      " looking for my soul mate.";
 }
 
 public String name() { return name; }
 public void setName(String n) {
  name = n;
 }
 
 public String sex() { return sex; }
 public void setSex(String s) {
  sex = s;
 }
 
 public String email() { return email; }
 public void setEmail(String e) {
  email = e;
 }
 
 public Boolean smoking() { return smoking; }
 public void setSmoking(Boolean s) {
  smoking = s;
 }
 
 public String descrip() { return descrip; }
 public void setDescrip (String d) {
  descrip = d;
 }
}

NOTE: in this example, we are overriding toString(). This might seem unimportant, but you may use this to print out class information when debugging. Be sure to override toString() in all your custom classes.

I will not cover the other file types in the File | New dialog because they are out of the scope of this column.

Save the file, and compile it to make sure it's error-free.

Importing Files

To import files into your project, simply drag the file from its current location into the file browser, under the proper group or folder. If the item to import is a Web Component, drag both the ".wo" folder and its associated Java file. Then, a dialog will pop up, asking what to do with the file. Be sure you click on the checkbox, indicating you wish to COPY the file (you don't want to reference files outside the project's folder).

You can accomplish the same thing by selecting the destination group or folder first, then going to menu Project | Add Files.

Referencing files outside the project folder is not always a bad thing, but I tend to avoid this because of the complications that may arise... Displaced or modified files may break the project. If you do want to reference a file outside the project folder, be sure to set the "reference style" to the proper value.

Removing files

To remove files from a project, follow these steps:

  • Go to the file browser and select your file (or ".wo" folder if it's a Web Component).
  • Press the Delete key.
  • If you want to dissociate the file from the project, it doesn't mean you want to physically erase it. Decide if you want to keep a copy or not. Then, in the dialog that pops up, click on "Delete" to erase the file, or "Don't Delete" to keep it on the disk. Both these two choices will detach the file from the project.

WARNING: Be really careful when removing files, because the operation cannot be undone. If you select the wrong file by mistake, it can be deadly... for your code!

Renaming Files

Always rename your files from within WebObjects. Select the file in the File Browser, then open menu Project | Rename. Enter the file name directly in the file browser. It is better to do this in WebObjects instead of the operating system, because the project file and makefile are automatically updated.

Finding Text

In the Project Builder editor, as in most text editors, you can search for an expression in your code by using the Find dialog. You can also "Find and Replace" using the same dialog. It is available in menu Find | Show Single File Find.

The most common features are available in it, like scope and case restrictions. You use it as any dialog of the sort, like the ones available in word processors for example. The dialog should remain open until you are done searching; you then have to explicitly close it.

You probably have seen already the tab marked "Find" in the Project Builder. This is the Batch Find tab. It does more than the Find dialog, because it can find a string in all files of the project. Go ahead and click on the Batch Find tab. This is also accessible from the menu, under Find | Show Batch Find.

This tab offers you roughly the same options as the regular Find dialog, plus it lets you decide where to look for things. To the right of the "Replace" field, you can choose to find a given word either:

  • Textually (anywhere in the files)
  • As a Regular Expression (with wildcards),
  • As a Definition (of a class or a member of a class)

Moreover, the Options button gives you many more choices for extending or restricting the scope of the search. You may search:

  • In the opened files
  • In the current project or all opened projects
  • In the frameworks
  • All files or only specified ones

Once you're done with specifying the restrictions, click on the Find button to start searching, or the Replace button to start replacing. The lines of code where the text was found will appear at the bottom of the pane. You may click on the lines you want to edit, and the Editor will let you modify that line, as the cursor will point to the line of code you chose. (This is similar to the Build tab, when clicking on an error.)

Indexes

To speed up searching, WebObjects keeps lists of all symbols, called indexes. Indexes are required when searching a definition, or for accessing symbols using the navigation bar.

By default these are automatically maintained every time you save or build a project. To force re-indexing, open menu Project, and choose items Remove Project Index, then Index Project .

Bookmarking Code

A bookmark lets you mark a line of code in a file, for later retrieval. To bookmark a line of code, just put the cursor on that line, then open menu Navigation | Add to Bookmarks. A new item will appear in the bookmarks tab.

To go back to that line of code, simply open the bookmarks tab and click on the right item. The editor pane will display the file in question, and the cursor will point to the line that was marked.

Copying and Renaming the Project

Sometimes you have to work on a copy of your project. The usual way of doing this is to copy the project folder to a different location or a different name. This is not sufficient; you also need to rename the project.

WARNING: You simply cannot have two projects with the same name on the same computer in WebObjects, even if the folder name is different. WebObjects will get confused and behave strangely at runtime ("I thought I fixed this bug! How come when I run the page it still looks like before I fixed it?"). After making a copy, be sure to rename the project to something else.

Copying a project implies simply copying its folder and then renaming the copy.

To rename a project:

  • Make sure it is closed.
  • Go to the Operating System (Finder) and select the folder of the project. Give it a new name.
  • Navigate inside the project folder and find the ".pbproj" file. Rename this file to the same name as the folder, and keep the extension ".pbproj".
  • This file is in reality a folder. To open this folder in Mac OS X, click on it while holding the control key, and then choose "Show package contents".
  • Locate the file project.pbxproj. Open this file with a text editor. Now find all occurrences of the old name for the project, and replace them with the new name.

Debugging

If you're like me, the first thing you do after writing some code in a new module (after compiling it successfully) is to fire up the debugger. You then place a breakpoint and watch the code as it runs through the module. If you don't see the code running, you can only assume it's working properly. Never assume...

Running the Debugger

Let's prepare for debugging. The targets are configured by default with the debugging information turned on. You can verify this by going to the targets tab, selecting one and clicking on the build settings tab. In this tab, there's a box called "generate debugging symbols". I suggest you always compile with "generate debugging symbol" checked, until you are ready to deploy your application on the production server.

"Generate debugging symbols" means the compiler should store the debugging information in the produced binary files.

You are now ready to fire up your application and to watch it run. From the Project Builder click on the Cleanup button, then on the Build button. When everything is done, click on the Debug button. The Debug tab will open, as shown in Figure 1 (after closing the File Browser and shrinking the editor):


Figure 1. Debug Tab.

As you can see, the application is currently running (check out the stop sign button). Look at all the stuff inside the debug tab:

  • The console tab. This contains both the output from the application and the debugger's output. The other tab (StdIO) contains only the application's output.
  • A list of threads. As the application runs, watch as the Console going wild with messages. This is normal.
  • For each thread, you have the stack of function calls
  • The list of variables, both for the current object and variables local to the current function.

Shortly after starting the debugger, a Web browser will come up, as it does when running the application the normal way.

Note that in this example, the current debugger is the Java debugger (JDB).

PREFERENCE: you can choose which debugger to use by going to the Project Builder, and opening the fist target. Then click on the Executables tab, and choose the Debugger tab. Choose between GNU or Java debuggers.

If you know the debugger that you chose to use, and all its commands, then you can type them in the Console tab inside the Debug tab. But it is easier to rely on the debugging toolbar, as we will see shortly. It contains the most useful functions of the debugger, and you don't have to type anything.

NOTE: If you are the keyboard type, you may prefer to type in your commands anyway. For help on the commands available for the Java debugger, just type in an invalid command, and the help will appear.

For help on the GDB's available commands, I suggest you use the help command:

  • help: displays a list of command categories
  • help aCategory: displays a list of commands for the specified category
  • help aCommand: displays the help for the specified command

Breakpoints

Adding a breakpoint

Running the application in debug mode without setting breakpoints is pointless. Stop the application Now let's set some breakpoints. Open the file where you want to set a breakpoint, like Main.java for example. Notice the editor now bears a margin on the left side of the code inside the editor. I call this the "breakpoint margin". Click on that margin, adjacent to the line you want to stop at. A gray arrow icon appears there , indicating a breakpoint. Check out Figure 2.


Figure 2. Breakpoints.

Note that there is a dark arrow (enabled breakpoint) and a pale arrow (disabled breakpoint). We'll talk about disabled breakpoints momentarily.

Now, go to your Browser, and reload the Main page. While WebObjects tries to create the Main component, calling the constructor, the execution stops where your breakpoint is located. The red arrow in the margin indicates the next line to be executed, the active line.

To continue the execution thereafter, simply click on the Pause button (on the right of the Run button) that looks like this while the program is paused. As long as it doesn't bump into another breakpoint, the application will carry on.

Removing breakpoints

To remove a breakpoint, simply click and drag the breakpoint arrow out of the breakpoint margin. You can also select it from the breakpoints tab and press Delete or Backspace.

Enabling and disabling breakpoints

As stated before, an enabled breakpoint appears as a dark arrow You can deactivate and reactivate breakpoints by clicking on the arrow repeatedly. When disabled, a breakpoint does not stop the code from executing.

You can also enable and disable breakpoints from the breakpoints tab, by clicking in the "Use" column (the checkmark means the breakpoint is enabled).

Retrieving a breakpoint

You can select a breakpoint in the breakpoints tab, and the editor jump directly to the line of code where the breakpoint is located. A disabled breakpoint serves a purpose similar to a bookmark.

Stepping Through the Code

Pausing the program

Alternately, you can pause the execution without using breakpoints, by clicking on the Pause button . Note that if you do this, it will be impossible to predict on what line you will end up. The only rational usage of the pause button is to detect infinite loops. If you suspect there's an infinite loop in your code, run the application, wait a while until you're almost certain the infinite loop is started, then click on the Pause button to see the line where it stopped.

Stepping over

The next thing you do when you're debugging is to watch the code execute line by line. Like I said, while the application is paused, the red arrow indicates the next line to be executed. You can execute the active line by clicking on the Step Over button . The pointer is now placed on the next line bearing a statement. Typically, you use the Step Over button to spy on the current function only. For example, you could witness if a condition is true, during an if() statement. You could also count the number of times the program passes in a while() loop.

Stepping into

If the line of code you are pointing to is a function, you can view the inside of the function by clicking on the Step Into button instead. The Project Builder will display the code for that function if it is available. If the current line is not a function, or if the code is not available, this button executes it just like a regular Step Over.

Stepping out

Say you're stepping into a function, and then you changed your mind and wish to skip the rest of the function, and go back to the caller's code. This is precisely what the Step Out button does. After clicking on Step Out, your active line should be the one immediately after the current function call, inside the caller's code.

Inspecting Variables

The other main usage of a debugger is to spy on the program's variables. WebObjects lets you inspect the contents of the variables in the variables pane inside the debug tab. The first level of this hierarchy shows two groups:

  • Arguments contains the list of parameters for the current method, plus "this" to represent the current object.
  • When "this" is a Web component (WOComponent), there's a member variable inside it, called context. It contains many useful things:
  • The Session object.
  • The Request object.
  • The Response object.
  • Locals contains the list of stack variable.

By expanding the hierarchy, you can spy on the value of all these objects and variables.

Moreover, when a variable is of a base type (int, float, char, etc., but not a class), you can actually change its value by double-clicking on the old value, and typing in a new one.

Lastly, every time you step trough the code one time, the values that were changed by this step turn to red. This is just to catch your attention.

Stack

To finish, let's explore the stack pane of the Debug tab. Using this pane, you can navigate through the stack and visit different contexts of the application at the period it halted. The top item of the list is the context when the application was paused (hence, the top of the stack). The row below is the calling function's context, and so on... Clicking on any row will bring you to the actual line of code in the editor (if the source code is available), also with the red arrow indicating the line being executed. Plus you will be able to access the variables that are available at that level of the stack.

The stack pane is also useful to understand what sequence of events lead to the call of the present function.

Next Month

An overview of the WebObjects Builder.


Emmanuel Proulx is a Course Writer, Author and Web Developer, working in the domain of Java Application Servers. He can be reached at emmanuelproulx@yahoo.com.

 
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.