Table of Contents
Previous Section
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.
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.
To create compiled code that can be integrated into a WebObjects application, you need to follow these basic steps:
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];
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.
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:
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.