Contents | ||
---|---|---|
|
Warning |
---|
This is deprecated information! |
Contents | ||||
---|---|---|---|---|
|
Info | ||
---|---|---|
| ||
Once you get the general idea of how a WebObjects application is setup, you'll want to add the incredibly powerful Project Wonder to any new application you start, but for the purposes of this tutorial, it is not necessary. |
...
...
...
In the left pane entitled WO Package Explorer, you will see a folder icon with your applications name. Click on the triangle next to your application's folder to see the organization of your project.
Note | ||||
---|---|---|---|---|
| ||||
The directory names outlined below are important because the ant build process for a WebObjects project assumes this naming convention. There's nothing to stop you calling those groups by other names like |
...
...
...
...
...
...
...
...
Info | ||
---|---|---|
| ||
This naming scheme ("Sources", "Resources", "WebServerResources", "Components", ...) is referred to as the "Fluffy Bunny" naming. This origins of this appellation are lost in the mists of time, but it is referred to in many places and it's good to know what on earth people are talking about! |
Without doing anything else, you have a WebObjects application ready to run. Select Run as... WOApplication by right-clicking on your Project folder or clicking on your project folder and then selecting Run from the menu bar.
...
As a note, when you are done testing an app, make sure you stop it by clicking the red square in the console window at the bottom of the Eclipse window. If you forget and try to run the app again you may get errors.
Well "Hello World" is about as boring a web page as one can make. So feel free to change it. In your project's Components window, you can edit the HTML of your component by double-clicking the component itself or it's related HTML file.
...
Figure 1-5 WOLips Component Editor
Well, there are certainly easier ways of making static web pages and using WebObjects for that purpose would defeat the purpose of developing using WebObjects. So let's start to learn how to make our pages a little more dynamic.
As mentioned before, the looks and functionality of a WebObjects component are defined by several files:
...
XCode's one redeeming feature regarding WebObjects was the WebObjects Builder. It allowed, in my opinion, the developer to quickly "wire-up" the HTML file. While editing, the HTML file, you could easily access methods and variables in the related Java file including the getter and setter methods, and quickly bind them to the component in the HTML document by clicking and dragging. In WOLips, this must all be done a bit more manually. As of OS X 10.5, WOBuilder is longer supported, but there is a movement to get an WOBuilder replacement project started.
Every WebObjects application includes a Main component by default. The HTML file is mostly empty except for "Hello World." Likewise, the Java file contains very little. We will learn how to add methods and variables to the component by building a very basic calculator.
Let's start by editing the Main.java file.
Code Block |
---|
public double firstUserInput;
public double secondUserInput;
|
Code Block |
---|
public double addResult(double firstUserInput, double senduserInput) {
double result = firstUserInput + secondUserInput;
return result
}
|
Code Block |
---|
// Generated by the WOLips Templateengine Plug-in at Mar 19, 2008 11:00:05 AM
package your.app.components;
import com.webobjects.appserver.WOComponent;
import com.webobjects.appserver.WOContext;
public class Main extends WOComponent {
private static final long serialVersionUID = 1L;
public double firstUserInput;
public double secondUserInput;
public Main(WOContext context) {
super(context);
}
public double addResult(double firstUserInput, double senduserInput) {
double result = firstUserInput + secondUserInput;
return result;
}
}
|
Figure 2-1 Figure 2-1 Main.java in the Eclipse Java Editor
Figure 2-2 The Eclipse Toolbar with WOLips installed
Figure 2-23 The Commands Associated with Component Icons
(You can find this list by clicking on Edit->Insert->)
...