Table of Contents Previous Section

Summary

When Do I Use Compiled Code?

The two primary reasons for using compiled code are boosting performance and being able to use your own custom classes.

You use compiled code when you want to subclass WOComponentController, WOWebScriptApplication, or WODynamicElement. You also use compiled code to provide your own custom business classes.

How Should I Partition My Application?

There are no hard and fast rules about how you organize a WebObjects application. However, it's common to implement your interface logic in WebScript and your business logic in compiled code.

What Do I Need to Do to Produce Compiled Code that Can Be Used in a WebObjects Application?

To create compiled code that can be integrated into a WebObjects application, you need to follow these basic steps:

  1. Use your development environment to create a project.
  2. Implement a main() function.
  3. Add to your project the libraries to which your application needs to link.
  4. Create your classes and add them to your project.
  5. Compile and link your code.

How Do I Access Compiled Code from Scripts?

You access compiled code from a script by getting an object of the class and sending it a message. For example:

// Return a Person object by invoking Person's personWithDictionary: method
aPerson = [Person personWithDictionary:newPerson]; 

// Send the object a message
[Person validate];

How Do I Access Scripts from Compiled Code?

To access a scripted object's methods from compiled code, you get the object that implements the method and then send it a message:

// Get the page object
id mainPage = [WOApp pageWithName:@"Main"];

// Send it a message
[mainPage setMessage:@"You have won a trip to Hawaii!!"];

To avoid compiler warnings, you can declare the scripted methods you invoke in your compiled code.

Can I Use C and C++ In a WebObjects Application?

Yes, but the interface you present to WebObjects must be Objective-C. You can integrate compiled C and C++ into your application in any of the following ways:

What Is the Most Efficient Way to Debug the WebScript Portion of My Application?

You debug your compiled code using the tools provided in your development environment. To debug the scripted portion of your application, the best technique is to use the logWithFormat: method. It's especially effective to use logWithFormat: to print the contents of self---this outputs all of the variables' values.

To see the output from logWithFormat:, you must run your application from the command line.