WEBOBJECTSDEVELOPER’S GUIDE
Chapter 6 Creating Reusable Components100The parentAction attribute identifies a callback method, one that the child component invokes in the parent wh
Intercomponent Communication101invoked by the child. In this example parentAction identifies the parent method named "respondToAlert", as spe
Chapter 6 Creating Reusable Components102Parent1’s Declarations File (excerpt)ALERT: AlertPanel {...parentAction = "respondToAlert";exitStat
Intercomponent Communication103For the sake of illustration, consider a page that displays a value in two different text fields—one provided by the par
Chapter 6 Creating Reusable Components104For instance, it’s sufficient in the example shown in Figure 31 to simply declare a childValue instance variab
Search Path for Reusable Components1054. Build the framework. If you perform a make install, it installs the framework in NeXT_ROOT/NextLibrary/Framew
Chapter 6 Creating Reusable Components106that were linked in to the application executable for a component with that name. For example, applications w
Designing for Reusability107• Provide attributes for all significant features. The more customizable a component is, the more likely it is that people
Chapter 6 Creating Reusable Components108This declaration specifies a value for just one attribute; all others will use the default values provided by
Managing StateChapter 7
11WebObjects is an object-oriented environment for developing and deploying World Wide Web applications. A WebObjects application runs on a server mac
111Most applications must be able to preserve some application state between a user’s requests. For example, if you’re writing a catalog application,
Chapter 7 Managing State112• Storing state information on the server. With each transaction, the web application locates the state information associa
Objects and State113Characteristically, WebObjects takes an object-oriented approach to fulfilling any of these state-storage requirements.Objects and
Chapter 7 Managing State114// Java DodgeLite Application.javapublic class Application extends WebApplication {public ImmutableHashtable dodgeData;publ
Objects and State115The WOComponent class defines a method application, which provides access to the component’s application object. So any component c
Chapter 7 Managing State116// WebScriptelapsedTime = [[self session] timeSinceSessionBegan];//JavaelapsedTime = this.session().timeSinceSessionBegan()
Objects and State117//Java exampleString componentName;Context context;String contextID;String elementID;String uniqueKey;context = this.context();com
Chapter 7 Managing State118Component Objects and Component StateIn WebObjects, state can also be scoped to a component, such as a dynamically generate
Objects and State119// Java DodgeLite Main.javaImmutableVector models, prices, types;MutableVector selectedModels, selectedPrices, selectedTypes;Strin
Introduction12client-side Java components that behave like dynamic elements, and how to design an application for deployment and improved performance.
Chapter 7 Managing State120// Java DodgeLite Main.javapublic Component displayCars() {SelectedCars selectedCarsPage = (SelectedCars)application().page
State Storage Strategies121• In cookies. State is embedded in name-value pairs (“cookies”) in the HTTP header and passed between the client and server
Chapter 7 Managing State122A Closer Look at Storage StrategiesTo compare and further understand state-storage options, look at the SessionStores samp
State Storage Strategies123applications—changing storage strategies midsession can cause errors. For example, imagine an application that stores state
Chapter 7 Managing State124• Page uniquing by implementing pageWithName: in the session object (see “pageWithName: and Page Caching” (page 138))A sign
State Storage Strategies125<FORM METHOD=Post ACTION=someAction>Can you guess my favorite digit?<BR><SELECT NAME="guesses">
Chapter 7 Managing State126• Backtracking. Because each page carries a record of the state existing at the time of its creation, backtracking can make
State Storage Strategies127See http://www.netscape.com/newsref/std/cookie_spec.html for a complete description of cookies.To use cookies, all you nee
Chapter 7 Managing State128NSData object is then asked for its ASCII representation. WebObjects pairs this data with names it generates and creates th
State Storage Strategies129// WebScript StateStorage FileSessionStore.wos@interface FileSessionStore:NSObject {id archiveDirectory;}- init;- archiveF
Other Useful Documentation13• WebObjects Tools and Techniques describes the development tools WebObjects Builder and Project Builder and shows how to
Chapter 7 Managing State130// Unarchive sessionrestoredSession = [NSUnarchiverunarchiveObjectWithData:archivedSession];return restoredSession;}- saveS
Storing State for Custom Objects131Storing State for Custom ObjectsWhen state is stored in the server, the objects that hold state are kept intact in
Chapter 7 Managing State132• During unarchiving, an EOEditingContext can recreate individual objects in the graph only as they are needed by the appli
Controlling Session State133You can see implementations of encodeWithCoder: and initWithCoder: in the DodgeDemo application, in the class ShoppingCart
Chapter 7 Managing State134much state is stored. This section takes a closer look at how you manage sessionwide state. Take care that your application
Controlling Component State135At times, a user’s choice signals the end of a session (such as when the Yes button is clicked in response to the query,
Chapter 7 Managing State136Adjusting the Page Cache SizeAs noted in “WebObjects Viewed Through Its Classes” (page 63), except for the first request, a
Controlling Component State137responsibility for maintaining any needed component state. For this reason, it’s rarely advisable to turn off page cachi
Chapter 7 Managing State138pageWithName: and Page CachingWhen the application object receives a pageWithName: message, it creates a new component. For
Controlling Component State139// example Application.java public Component pageWithName(String aName) {Component aPage;if (aName == null) aName = &quo
Chapter 7 Managing State140A WebObjects application handles a page-refresh request differently than it would a standard request. When the application
Creating Client-Side ComponentsChapter 8
143In earlier chapters, you learned about client-side Java components. Client-side components are Java applets that your application can use instead o
Chapter 8 Creating Client-Side Components144destination applets are. To determine these, it inspects the visible applets on the page and looks for som
When You Have an Applet’s Source Code1451. In Project Builder, add the ClientSideJava subproject to your project. To do so, double-click the word “S
Chapter 8 Creating Client-Side Components146The value for a key must be a property-list type of object (either singly or in combination, such as an ar
When You Don’t Have an Applet’s Source Code1471. Declare a subclass of the Association class.class MyAssociation extends Association {...}2. Implement
Deployment and Performance IssuesChapter 9
WEBOBJECTS ESSENTIALS
151After you’ve written your application, tested it, and verified that it works properly, it’s ready to be deployed for use by your customers. Before y
Chapter 9 Deployment and Performance Issues152Accessing StatisticsIf your application has a WOStats page, you can look at the statistics that WOStatis
Recording Application Statistics153// WebScriptNSDictionary *myDict = [[[self application] statisticsStore] statistics];// JavaImmutableHashTable myDi
Chapter 9 Deployment and Performance Issues154Error HandlingWhen an error occurs, WebObjects by default returns a page containing debugging informatio
Automatically Terminating an Application155Automatically Terminating an ApplicationUnless an application is very carefully constructed, the longer it
Chapter 9 Deployment and Performance Issues156users to be able to end their sessions first, you might write the following code:// WebScript Application
Performance Tips157component’s template (the result of parsing the .html and .wod files) and information about resources the component uses. If you cac
Chapter 9 Deployment and Performance Issues158Limit State StorageAs the amount of memory required by an application becomes large, its performance dec
Installing Applications159Consider implementing a batching display mechanism to display the information in the table. For example, if the array contai
Chapter 9 Deployment and Performance Issues160NeXT_ROOT/NextLibrary/WOApps. Thus, you can install the entire directory under <DocRoot>/WebObject
WEBSCRIPT
The WebScript LanguageChapter 10
165To speed the development cycle, you may want to write your application in a scripting language. The WebObjects scripting language is called WebSc
Chapter 10 The WebScript Language166id number, aName;- awake { if (!number) {number = [[self application] visitorNum];number++;[[self application] set
WebScript Language Elements167In these declarations, id is a data type. The id type is a reference to any object—in reality, a pointer to the object’s
Chapter 10 The WebScript Language168The scope of an instance variable is object-wide. That means that any method in the object can access any instance
WebScript Language Elements169// assign another variable to a variablemyVar = anotherVar;// assign a string constant to a variablemyString = @"Th
What Is a WebObjects Application?Chapter 1
Chapter 10 The WebScript Language170For more information on NSNumber, NSString, NSDictionary, and NSArray, see the chapter “WebScript Programmer’s Qui
WebScript Language Elements171•A return type of void is not allowed:// This won’t work either.- (void) aMethod:(NSString *)anArg { ... }Both example m
Chapter 10 The WebScript Language172automatically defines two accessor methods: one to retrieve the instance variable’s value, and one to change the va
WebScript Language Elements173aString = [NSString stringWithString:@"Fred"];Note that a class is represented in a script by its correspondin
Chapter 10 The WebScript Language174// Create a mutable stringstring = [NSMutableString stringWithFormat:@"The string is %@", aString];// Cr
WebScript Language Elements175Explicitly specifying a class in a variable or method declaration is called static typing.Because variables and return v
Chapter 10 The WebScript Language176Control-Flow StatementsWebScript supports the following control-flow statements:ifelseforwhilebreakcontinuereturnAr
WebScript Language Elements177In WebScript, relational operators are only reliable on NSNumbers. If you try to use them on any other class of object,
Chapter 10 The WebScript Language178The postincrement and postdecrement operators are not supported. They behave like the preincrement and predecremen
WebScript Language Elements179[self application]WOComponent also defines a session method, so you can do this to retrieve the current session:[self ses
Chapter 10 The WebScript Language180Modern:function submit() {// <body>}• Method Definition With ArgumentsClassic:- takeValuesFromRequest:(WORequ
Advanced WebScript181Note that in this last example the left parenthesis should occur at a break between words when the modern message maps to an exis
Chapter 10 The WebScript Language182@interface Surfshop:NSObject {id name;NSArray *employees;}@end@implementation Surfshop- (Surfshop *)initWithName:a
WebScript for Objective-C Developers183The following example is a simple category of WORequest that gets the sender’s Internet e-mail address from the
Chapter 10 The WebScript Language184Here are some of the more subtle differences between WebScript and Objective-C:•You don’t need to retain instance
WebScript for Objective-C Developers185•You can only use the “at sign” character (@) as a conversion character with methods that take a format string
Chapter 10 The WebScript Language186To access a component’s methods, you must store the component in the session and then access it through the sess
WebScript Programmer’s Quick Referenceto Foundation ClassesChapter 11
189As you learned in the previous chapter, when you write an application in WebScript, all values are objects, even simple values such as numbers or s
19WebObjects is a product that makes it easy for you to write dynamic web-based applications (or WebObjects applications). Before you start programmin
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes190Determining EqualityYou can determine if two objects are equal using the isE
Working With Strings191Note: The configuration of your HTTP server determines the user who owns autostarted applications. Reading From FilesThe string,
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes192Commonly Used String MethodsThe following sections list the most commonly us
Commonly Used String Methods193+ stringWithContentsOfFile:Returns a string created by reading characters from a specified file. For example, the followi
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes194– substringFromIndex:Returns a string containing the characters of the recei
Commonly Used String Methods195Modifying StringsWarning: The following methods are not supported by NSString. They are available only to NSMutableStri
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes196Working With ArraysNSArray and NSMutableArray objects manage immutable and m
Commonly Used Array Methods197Creating ArraysThe methods in this section are class methods, as denoted by the plus sign (+). You use class methods to
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes198– isEqual:Returns YES if the specified object is an array and has contents eq
Commonly Used Array Methods199– insertObject:atIndex:Inserts an object at a specified index. If the specified index is already occupied, the objects at
Apple, NeXT, and the publishers have tried to make the information contained in this manual as accurate and reliable as possible, but assume no respon
Chapter 1 What Is a WebObjects Application?20The following sections describe the WebObjects application ingredients in more detail.ComponentsTo write
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes200Storing Arrays– writeToFile:atomically:Writes the array’s string representat
Commonly Used Dictionary Methods201the key’s value. Within a dictionary, the keys are unique. That is, no two keys in a single dictionary are equivale
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes202Creating DictionariesThe methods in this section are class methods, as denot
Commonly Used Dictionary Methods203Querying Dictionaries– allKeysReturns an array containing the dictionary’s keys or an empty array if the dictionary
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes204– isEqual:Returns YES if the specified object is a dictionary and has content
Commonly Used Dictionary Methods205– removeObjectForKey:Removes the entry for a specified key.– removeObjectsForKeys:Removes the entries for each key i
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes206Working With Dates and TimesNSCalendarDate objects represent dates and times
Commonly Used Date Methods207Commonly Used Date MethodsThe following sections list some of the most commonly used methods of NSCalendarDate, grouped a
Chapter 11 WebScript Programmer’s Quick Reference to Foundation Classes208Representing Dates as Strings– descriptionReturns a string representation o
Commonly Used Date Methods209– minuteOfHourReturns the NSCalendarDate’s minutes value (0–59).– secondOfMinuteReturns the NSCalendarDate’s seconds val
The Ingredients of a WebObjects Application21files. A component may not need a code file at all; it may need only a template file and a declarations file.
213Index%@ 59.api file 20.html file 20, 21.wo directory, See wo directory.woa directory, See woa directory.wod file, See wod file.wos file, See cod
Index214synchronization 85, 102–104client-side 85–86template 82–83URL, specifying 53variables 118–120in reusable components 97componentsJoinedBy
215IndexinitObject:withCoder: method 132initWithCoder: method 132–133example 133input postprocessing 51insertObject:atIndex: method 199install 1
Index216Rrecording statistics 151–153refuseNewSessions: method 155regenerating request page 45registerForEvents method 73relational operators 176
217IndexstringWithContentsOfFile:method 190–191, 193stringWithFormat: method 192stringWithString: method 192subclass, definition 166substringFromI
Index218terminateAfterTimeInterval:method 155trace methods 59–60WOAssociation 71, 84–85WOComponent 23–24, 69–71, 82–87, 105See also componentsappe
Chapter 1 What Is a WebObjects Application?22as shown in Figure 2. (In Project Builder, Java and Objective-C code files are shown under Classes instead
The Ingredients of a WebObjects Application23Application CodeIn addition to having one or more components, your application can also include applicati
Chapter 1 What Is a WebObjects Application?24where they are used by reading the chapter “WebObjects Viewed Through Its Classes” (page 63).Components a
Running a WebObjects Application25Now you’ve learned what a WebObjects application looks like and seen the pieces that you’ll have to write. The next
Chapter 1 What Is a WebObjects Application?26Figure 5. Chain of Communication Between the Browser and Your WebObjects ApplicationHere is a brief desc
Running a WebObjects Application27Internet Server API (ISAPI). Thus, WebObjects adaptors can take advantage of server-specific interfaces but still pro
Chapter 1 What Is a WebObjects Application?28associated with the user’s action, and generates a response—usually an HTML page (see Figure 8).Figure 8.
Dynamic ElementsChapter 2
Contents
31In the previous chapter, you learned that a WebObjects application is made up of components, which in turn are made up of dynamic elements. Dynamic
Chapter 2 Dynamic Elements32This list is not hard-coded into the page. Instead, it is produced by several dynamic elements. Figure 10 shows how this s
Server-Side Dynamic Elements33Figure 11. Server-Side Dynamic ElementsHow Server-Side Dynamic Elements WorkTo learn how server-side dynamic elements
Chapter 2 Dynamic Elements34In the .wod file, each element is identified by name and then its type is specified. The outermost dynamic element in the HTM
Server-Side Dynamic Elements35Finally, the WOString element defines a value attribute, which specifies the string you want displayed. This value attribu
Chapter 2 Dynamic Elements36• It resolves the value for the upSince key by looking for a method named upSincein the application object. If the method
Client-Side Java Components37elementName : elementType { attribute = value;attribute = value };Notice that the last attribute/value pair before a clos
Chapter 2 Dynamic Elements38When client-side components are used, an HTTP request can result in either the resynchronization of state or the return of
Client-Side Java Components39When you look at client-side component’s bindings in the .wod file, it looks like this example:INPUTFIELD : WOApplet {code
Common MethodsChapter 3
43The methods that you write for your WebObjects application provide the behavior that makes your application unique. Because you are writing subclass
Chapter 3 Common Methods44name and click the button. This initiates the application’s request-response loop, and sayHello is invoked. Action methods t
Action Methods45// Java examplepublic Component showPart() {Error errorPage;Inventory inventoryPage;if (isValidPartNumber(partNumber)) {errorPage = (E
Chapter 3 Common Methods46Initialization and Deallocation MethodsLike all objects, WOApplication, WOSession, and WOComponent implement initialization
Initialization and Deallocation Methods47- awake {/* initializations go here */}public void awake () {/* initializations go here. */}Application Initi
Chapter 3 Common Methods48// WebScript DodgeDemo Application.wos - awake {++requestCount;[self logWithFormat:@"Now serving request %@", requ
Initialization and Deallocation Methods49Component InitializationA component object’s init method is invoked when the component object is created. Jus
vTable of ContentsIntroduction 9About This Book 11Other Useful Documentation 12Part I WebObjects EssentialsWhat Is a WebObjects Application? 17The In
Chapter 3 Common Methods50or null in Java). For more information, see the chapter “Managing State” (page 109).Request-Handling MethodsRequest-handling
Request-Handling Methods51As you implement request-handling methods, you must invoke the superclass’s implementation of the same methods. But consider
Chapter 3 Common Methods52Invoking an ActionThe second phase of the request-response loop involvesinvokeActionForRequest:inContext:. WebObjects forwar
Request-Handling Methods53following action method, the “CreditCard” component sets the verifiedsession variable to YES when the user has supplied valid
Chapter 3 Common Methods54appendToResponse:inContext: method adds bold and italic markup elements around a string’s value as follows: id value;id esca
Debugging a WebObjects ApplicationChapter 4
57In the previous chapters, you learned the pieces of a WebObjects application and the kinds of methods you need to write. Once you’ve put together an
Chapter 4 Debugging a WebObjects Application58executable in the launch panel. Output from the debugging methods appears in the launch panel. Debugging
Debugging Techniques59In WebScript and Objective-C, logWithFormat: works like the printf() function in C. This method takes a format string and a vari
viHow WebObjects Works—A Class Perspective 72Starting the Request-Response Loop 72Taking Values From the Request 73Accessing the Session 74Creating or
Chapter 4 Debugging a WebObjects Application60methods are useful if you want to see all or part of the call stack. The following table describes the t
Programming Pitfalls to Avoid61•WebScript supports only objects that inherit from NSObject. As most objects inherit from NSObject, this limitation is
Chapter 4 Debugging a WebObjects Application62• The pageWithName method creates the page by looking up and instantiating the component class that has
WebObjects Viewed Through Its ClassesChapter 5
The Classes in the Request-Response Loop65As you learned at the end of the first chapter, WebObjects applications respond to HTTP requests from the ser
Chapter 5 WebObjects Viewed Through Its Classes66Figure 14. Request-Response Loop: Application and Server LevelThe HTTP server sends a request to the
The Classes in the Request-Response Loop67Figure 15. Request-Response Loop: Session LevelThe objects dedicated to session management ensure that stat
Chapter 5 WebObjects Viewed Through Its Classes68When a user makes an initial request to a WebObjects application, the application creates a session o
The Classes in the Request-Response Loop69• WOResponse (in Java, Response)Stores and allows the modification of HTTP response data, such as header info
viiPart III WebScriptThe WebScript Language 163Objects in WebScript 165WebScript Language Elements 166Variables 166Variables and Scope 167Assigning Va
Chapter 5 WebObjects Viewed Through Its Classes70Figure 17. Request-Response Loop: Page LevelTwo major branches of these objects descend from WOEleme
The Classes in the Request-Response Loop71• WOAssociation (in Java, Association)Knows how to find and set a value by reference to a key. Instance varia
Chapter 5 WebObjects Viewed Through Its Classes72dynamic elements on your page and the objects in the Enterprise Objects Framework.• EOEditingContext
How WebObjects Works—A Class Perspective73HTTP server and the WOApplication object. The application first parses the command line for the specified adap
Chapter 5 WebObjects Viewed Through Its Classes74Figure 19. Taking Values From the RequestA cycle of the request-response loop begins when the WOAdap
How WebObjects Works—A Class Perspective75Figure 20. URL to Start a WebObjects ApplicationThis URL does not contain a session ID, so the application
Chapter 5 WebObjects Viewed Through Its Classes76transactions from that of another, session IDs must not be easily predicted or faked. To this end, We
How WebObjects Works—A Class Perspective77class for the page named “Main.” The application object performs the following steps to create a component:1
Chapter 5 WebObjects Viewed Through Its Classes78subscription for a friend. You follow the process a second time, selecting a different publication an
How WebObjects Works—A Class Perspective79For more on how components are associated with templates, and on how HTML elements participate in request-ha
Chapter 5 WebObjects Viewed Through Its Classes80message and invoke the appropriate action method in the request component. This action method returns
How WebObjects Works—A Class Perspective811. The application object stores the response component indicated by the action method’s return value. (This
Chapter 5 WebObjects Viewed Through Its Classes824. It saves the session object in the session store. 5. It invokes its own sleep method.When an Objec
How HTML Pages Are Generated83Figure 25. An Object Graph for a Page’s TemplateThe template is created at runtime when the component is first requested
Chapter 5 WebObjects Viewed Through Its Classes84Associations and the Current ComponentA dynamic HTML element, such as a text field or a pop-up button,
How HTML Pages Are Generated85START:Calendar {selectedDate = startDate;callBack = "mainPage";};In this example, Main is the parent component
Chapter 5 WebObjects Viewed Through Its Classes86associate particular events in the client applet (such as clicking a button) with the invocation of m
How HTML Pages Are Generated87Figure 26. An Object Graph for a Page With a Subcomponentpage templatecalendartemplatecalendarinstancecalendarinstancep
SPECIAL TASKS
Introduction
Creating Reusable ComponentsChapter 6
93In the simplest applications, each component corresponds to an HTML page, and no two applications share components. However, one of the strengths of
Chapter 6 Creating Reusable Components94Figure 27. A Navigational ControlThe HTML code for one page might look like this:<HTML><HEAD><
Benefits of Reusable Components95<HTML><HEAD><TITLE>World Wide Web Wisdom, Inc.</TITLE></HEAD><BODY>Please come vis
Chapter 6 Creating Reusable Components96the World Wide Web Wisdom company could change the look of the navigational controls in all of its application
Benefits of Reusable Components97Figure 28. An Alert PanelThis panel is similar to the navigation table shown in Figure 27, but as you’ll see, most of
Chapter 6 Creating Reusable Components98the alertTitle and infoString attributes (leaving the other attributes private) using this AlertPanel.api file:
Intercomponent Communication99For reusable components to be truly versatile, there must also be a mechanism for the child component to interact with t
Kommentare zu diesen Handbüchern