). Creating Hyperlinks Creating Hyperlinks There are two types of hyperlinks that you can use in a WebObjects application: • A static hyperlink (which uses the HTML tag), whose destination is constant. • A dynamic hyperlink (WOHyperlink), whose destination can be specified at run time. See “Dynamic Hyperlinks”for more information about these. To create a static hyperlink: 1. Click on the toolbar. 2. Type the text that the hyperlink should contain. As you type, the text is underlined. 3. Click again. Chapter 2 Editing With WebObjects Builder Setting Page Attributes The top level in the element hierarchy is always the page itself. To inspect a page’s attributes: 1. Select any element in the page. 2. In the Inspector, click the leftmost icon in the element path. (If necessary, click the Inspector button in the toolbar to display the Inspector.) Click here to display Page Attributes. Click here to make the title a dynamic string. Setting Colors Setting Colors WebObjects Builder allows you to set the colors for a page’s background, selected text, and hyperlinks. To set the color of selected text in the component window, click in the border of the color well Attributes Inspector. in the toolbar. To set other colors, use the Page Clicking the border of any color well brings up the Colors panel. You can drag colors between this panel and any color well. These buttons provide different ways to select colors. Chapter 2 Editing With WebObjects Builder Click to display this palette. Drag an item onto the window to insert into the component. The icons at the top of the palette window show the available palettes. To select a palette, click its icon. Two pre-configured palettes are provided: Java clientside components and components from the WOExtensions framework. Palettes If the palette’s background is gray, you can’t make any changes to it. To enable editing, choose Palettes m Make Editable. The palette's background changes to white and its title says “Alt-drag to insert item.” Note: When you first create a palette, it is editable until you save it. 2. In the component window, select the element or elements that you want to add to the palette. 3. Hold down the Alt key and drag the selection to the palette. Chapter 2 Editing With WebObjects Builder Note: If the palette is editable, you can drag the item to the window, but it will disappear from the palette. 2. Drag the item from the palette to the location in the component window where you want it to appear. Changing a Palette Icon You can replace the icon of any palette, or any item in a palette, with an image of your own choosing. To do so: 1. Open the palette window and select the palette whose icon you want to change. 2. Make the palette editable. 3. Chapter 3 Working With Dynamic Elements Introduction to Dynamic Elements A dynamic element is an element whose exact HTML representation isn’t determined until run time. Dynamic elements are represented in the HTML template by the tag . There are several types of dynamic elements that you can use in your WebObjects applications. Some of them (such as dynamic forms or images) have counterparts in standard HTML ( Chapter 3 Working With Dynamic Elements For example, a dynamic hyperlink (WOHyperlink) has an action attribute that specifies an action method in the application that is executed when the user clicks the link. The process of associating an attribute with a variable or method in your code is called binding. WebObjects Builder provides tools to make it easy for you to create bindings. Information about your bindings is stored in the declarations (.wod) file in your component. Creating Dynamic Elements In addition, you can also drag a model file (of type .eomodeld) into a component to create a variable of type WODisplayGroup (see “Adding Display Groups”). Certain file types (such as .gif, .jpeg, .tif, .eps, and .bmp) are automatically recognized by WebObjects Builder. The Preferences Panel (which you display by choosing Tools m Options) shows a list of file extensions that WebObjects Builder accepts. Chapter 3 Working With Dynamic Elements The element appears in the HTML template. A template appears in the lower pane (the declarations file) showing the bindable attributes of the element. Elements in brackets are optional. See “Binding Elements” for more information on bindings. Note: You must type in the bindings of all the attributes you want to bind, and delete the others. Otherwise, you will not be able to switch back to graphical editing mode or save the file. Element appears in HTML source view. Chapter 3 Working With Dynamic Elements The first column of the object browser displays two types of objects: • Keys are displayed above the horizontal line. A key can be either an instance variable or a method that returns a value. • Actions are displayed below the line. An action (or action method) is a method that takes no parameters and returns a component (the next page to be displayed). Chapter 3 Working With Dynamic Elements Choose a command from this menu to add objects to your source code or view the code. There are several ways to add items to the object browser: • Use Project Builder to add keys and actions to your component’s source file. When you save changes to a source file, WebObjects Builder parses the file, detects items that have been added and deleted, and updates the object browser’s display to reflect the changes. Chapter 3 Working With Dynamic Elements When you choose Add Variable/Method, the following panel opens: Type the variable name here. Click one of these buttons if your variable is an array. Choose the variable’s type from this pop-up list. Check one or more of these boxes. In this panel, you specify: • The name of the key. • Its type. You can choose the type from the pop-up list or type it in directly. You can also use the radio buttons to specify whether the variable is an array. Chapter 3 Working With Dynamic Elements Instance variable. Method returning value of instance variable. Method setting value of instance variable. When you choose Add Action, the following panel appears: Enter the action method’s name here. Select response page name from pop-up menu (use null or nil to return same page). When you click Add, the following code is added to your source file: WebObjects Builder provides these ways to add variables and methods for your convenience. Chapter 3 Working With Dynamic Elements Note: To delete a key or action, you must delete it from the source code in Project Builder. Also, the Add Variable/Method and Add Action commands apply only to a component’s code file. To add variables and methods to the application and session code files, or to any other code files, you must edit them directly in Project Builder. Adding Display Groups A display group is an important type of variable that you use in WebObjects applications that access databases. Chapter 3 Working With Dynamic Elements • Drag a model (a folder with the extension .eomodeld) from the file system into the object browser in your component window, or drag an entity from the EOModeler application into the object browser. When you do this, a panel asks you if you want to add the model to your project. If you reply Yes, the Add Display Group panel appears. Enter the display group’s name. Click here to add the display group and configure it. Chapter 3 Working With Dynamic Elements Choose an entity from the project’s models to create an enterprise object based on that entity. Choose this item to create a display group object. In the figure, if you choose the entity CarPackage as the variable’s type, the following code gets added to your source file: /** @TypeInfo CarPackage */ protected EnterpriseObject myCarPackage; The variable myCarPackage is declared as type EnterpriseObject. Chapter 3 Working With Dynamic Elements In the object browser, means that the display group has been configured. A means that it has not been configured, and so the variable isn’t automatically created. A configured display group shows its keys and actions in the second column of the object browser. You can bind them to elements in your program. Unconfigured display Configured group (double-click to display group configure). Display group’s keys Display group’s actions. Chapter 3 Working With Dynamic Elements • Entity: The Entity combo box has a list of entities from the models in your project. You can select one from the list or type the name. • Has detail data source: Check this to create a detail display group. See “Creating a Detail Display Group” for more information. • Entries per batch: Set a non-zero value here to specify the number of records to be displayed at once. When the value is zero, all records are displayed. Chapter 3 Working With Dynamic Elements Drag relationship from EOModeler into component to create detail display group. This example creates a detail display group based on the movieRoles relationship, with Movie as the master entity and MovieRole as the detail entity. As with other display groups, you can use the Display Group Options panel to immediately configure the newly created display group. Binding Elements This section discusses the basic techniques you use to bind elements. Chapter 3 Working With Dynamic Elements In the figure, you have added a dynamic text field (WOTextField) to your component. Note the blue triangle in the top left corner, which distinguishes the dynamic text field from a static HTML text field. The long rectangle surrounding the text field represents the form of which it is a part. To bind the text field to the variable myVar: 1. Click myVar in the object browser and drag to inside the text field. Default attribute is selected automatically. Chapter 3 Working With Dynamic Elements window. Some (not all) dynamic elements display the binding for their default attribute inside the element itself. Binding of text field’s default attribute. Click to see documentation on Click to add attribute to this dynamic element. element. 4. If you change your mind, you can click the Inspector’s Disconnect button (which changed from Connect Variable) to undo the binding. Binding Elements This time, a different attribute is selected, since the default attribute has already been bound. 2. Click Connect Variable to bind the selected attribute. 3. If, instead, you want to bind an attribute that has already been bound, double-click its row, and the old binding is replaced with the new one. You can also bind an element’s attributes by typing in the Inspector without going through the dragging procedure. To do this: 1. Chapter 3 Working With Dynamic Elements • Keys must specify their full key path. For example, to bind the key that is selected in the following figure, you would type session.selectedSailboards.count Creating Form-Based Dynamic Elements In HTML, a form is a container element (one that can contain other elements). Dynamic and Static Inspectors WOForm itself, don’t receive information but contain an action attribute representing an action to be taken when the form is submitted. You bind form-based elements by the process described in “Binding Elements”. Tip: HTML forms don’t allow you to have multiple submit buttons in a single form, but the WebObjects WOForm element does. If you want multiple submit buttons in a form, bind the multiplesubmit attribute of WOForm to the value YES (by typing it in the Inspector). Chapter 3 Working With Dynamic Elements Select Dynamic Inspector to set the WOText’s bindings. Set HTML attributes of text area here. To switch back to the WOText Inspector, select Dynamic Inspector from the pop-up list. In addition, you can convert any dynamic element into its static counterpart, or vice versa: • When inspecting a dynamic element, if you click Make Static, the element becomes its static counterpart (if it has one), and the Static Inspector appears. Creating Other WebObjects Static Element Dynamic Counterpart Select WOBrowser, WOPopupButton Hyperlink WOHyperlink Applet WOApplet Other Generic WebObject If you convert a static element to its dynamic counterpart by clicking Make Dynamic, and there is no direct counterpart, the element becomes a generic WebObject whose element name is the HTML tag for the static element (see “Generic WebObjects”). In this figure, a list element ( ) has been converted to a generic WebObject element. Chapter 3 Working With Dynamic Elements To create a dynamic element, you click its toolbar icon. One thing to be aware of is what happens when there are already elements selected when you create the element: • Some dynamic elements (WOHyperlink, WOConditional, WORepetition, custom WebObjects and generic WebObjects) can contain other elements. In this case, the selected elements appear with the new element “wrapped” around it. Creating Other WebObjects time. A WOString is abstract in that it doesn’t represent any specific element, but it can be contained in any other HTML element that can contain text. WebObjects Builder provides a shortcut for binding the value attribute of a WOString, since it is by far the most common attribute you bind. Drag to here to bind value attribute directly. Instead of dragging to one of the icons, drag to the center binding box. Chapter 3 Working With Dynamic Elements Repetitions A repetition (WORepetition) is a container element that repeats its contents a certain number of times. It is like a loop in a structured programming language. Repetitions are one of the most important elements in WebObjects, since it is quite common for applications to display repeated data (often from databases) when the amount of data to be displayed isn’t known until run time. Creating Other WebObjects When you wrap a repetition around a table row, the repetition symbol doesn’t appear. Instead, a blue border appears around the row. To bind the repetition, drag from the object browser to anywhere in the row (but not to a dynamic element inside the row). The Inspector appears, allowing you to complete the binding as usual. Select a table row, then click here to create a repetition around the row. The blue border and background means the row is in a repetition. Chapter 3 Working With Dynamic Elements the WOConditional’s contents are displayed. If condition is false (0), the contents aren’t displayed. condition can be bound to a variable or to method that returns a Boolean value. (WebScript and Objective-C use the constants YES and NO; Java uses true and false.) To bind condition (or any other attribute that takes a Boolean) to a constant value, enter YES or NO in the bindings Inspector. To create a conditional, click in the toolbar. Creating Other WebObjects Custom WebObjects You use custom WebObjects for two main purposes: • To implement WebObjects element classes not directly supported by WebObjects Builder. • To implement reusable components (see “Reusable Components” for more details). To create a custom WebObject: 1. Click in the toolbar. A template for a custom WebObject appears at the insertion point. 2. In the Custom WebObject Inspector, specify the element class. Select class name from the list or type it. Chapter 3 Working With Dynamic Elements the WOExtensions framework, which is included in your project by default. If WebObjects Builder recognizes the element class, it automatically displays its attributes. Otherwise, you can add them by clicking Add Attribute. The WOExtensions palette (see “Palettes”) contains several pre-defined custom WebObjects elements you can use in a component. Generic WebObjects You can use the generic WebObject element to create a dynamic version of any HTML element. Creating Other WebObjects 1. Click in the toolbar. 2. Bring up the Inspector. Enter the element name here. Click to add attributes. A generic WebObject element has one required attribute, elementName, which specifies what type of element should be generated at run time. For example, imagine that a future version of HTML adds a container element called , which you would like to generate dynamically in your component. You would: 3. Type BLOB between the quotes in the Binding column. Chapter 3 Working With Dynamic Elements Dynamic Images The elements WOImage and WOActiveImage are dynamic images. At run time, WOImage is rendered as a passive image and WOActiveImage as a mapped, active image. To create them, click respectively. or in the toolbar, A static image element requires you to specify its pathname directly in the HTML. With dynamic images, you bind the filename attribute to specify the name of an image file in your project, or in a framework. Reusable Components appears in your component, with its code attribute set to the name of the file. • Drag an element from the Client-Side Components palette to your component (see “Palettes”). Reusable Components One of the strengths of the WebObjects architecture is its support of reusable components. Any component that you define, whether it represents an entire page or part of a page, can be reused by any WebObjects application. Chapter 3 Working With Dynamic Elements • Use the toolbar to add a custom WebObject element (see “Custom WebObjects”) to your page, then use the Inspector to set its type to the name of the reusable component. • Drag a component that has been stored on a palette to the component window (see “Palettes”). A component that is designed for reuse can export keys and actions, which become attributes that the parent component can bind, just as it would set the attributes of any other dynamic element. Reusable Components Name of shared component. Parent component can bind to these attributes. Shared component appears inside Custom WebObject icons. The Inspector shows the child component’s attributes. As with any other dynamic element, you can bind the child component’s attributes to keys and actions in the parent component’s code. |