[Contents] [Previous] [Next] [Last]

Chapter 4
Working with Projects
and Components

This chapter explains how to set up projects and explores alternatives for adding and editing pages, components, and other objects.

You can add HTML pages to a project by creating them, or by importing existing pages into the project. You can also import image files, and all of the other files that are part of a project. See "Adding Pages and Files to a Project."

You can use the Page Editor to build HTML pages. There are many options for adding components, as well as text, images, links, and other HTML tags to a page, and for formatting and modifying the page. See "Editing Pages."

A number of components are provided with the default distribution of Visual JavaScript, and more can be added or imported. To help you understand and choose components, the built-in components are described briefly in "Overview of Built-in Components", and in more detail in Part 2, "Component Library Reference."

When you have added components to a page, you can customize them using the Inspector, or, in some cases, custom component editors. See "Editing Components." You can also use the Inspector to examine and change the properties of non-component objects such as projects and pages. See "Inspecting Other Objects."

Adding Pages and Files to a Project

There are several ways to add pages to a project. You can create blank pages or new pages based on templates and specify their contents by editing them, you can use the Database Application Wizard to generate database-access pages automatically, or you can reuse or modify existing pages by importing them into your project.

As you add most kinds of components to pages, the source files that are required by those components are automatically added to the project. You can see the source files listed in the Project window, under the file type.

Image components on pages refer to an image file (.gif or .jpeg) that can either be loaded from an absolute URL or added to and deployed with the project. To add an image file to a project, import it as you would an HTML page. For more information on importing files and pages, see the next section, "Importing Page and Image Files."

Importing Page and Image Files

To import an HTML page, image file, or code file into a project, do any of the following:

The Import Files to Project dialog box appears, as shown in Figure 4.1.

Figure 4.1    The Import Files to Project dialog box

When you import a page, related files such as images and linked pages can be imported with the page. Follow these steps to specify which file or files to import.

  1. Select the method with which you want to import (file copy or HTTP) from the drop-down list.

  2. Specify the complete path to the page or file you want to import. If you are using file copy, you can click Browse to search the file system and select a page or file.

    If you are importing a page, any images or files that are referenced in that page are also imported, as long as they are found in or under the same directory as the page. (You can choose to import images or files from further up the directory structure. See "Importing Additional Related Files" following.)

  3. Optionally, select "Import linked pages." When you select this option, additional pages that are linked to the primary page are also imported, as long as they are found in or under the same directory as the page.

  4. Click OK to import the page or file. The imported HTML page or file appears in the project tree along with its associated files.
By default, the specified page and related files that are found in or below the same directory are imported to the top level of the project directory. Related files that are not in or under the same directory as the specified page are not imported.

Importing Additional Related Files

By default, only those referenced files that are found in or below the same directory as the primary page are imported. You can choose to import related files from further up the directory structure. This is called increasing the scope of the import. For example, suppose the main page you want to import refers to an image, and the files are located as follows:

C:\MyHost\MyProjects\ProjectA\MyPage.htm
C:\MyHost\MyProjects\globals\picture.jpg
To import this page with its image, you must import from the point where the directory structure branches:

C:\MyHost\MyProjects\
This part of the directory structure defines the scope of the import. When you define a scope, the part of the directory structure below the scope is recreated in the project directory, in order to keep the same relative positions of related files.

Follow these steps to import files from further up the directory structure:

  1. Select the method and page in the Import Files to Project dialog box.

  2. In the "Increase scope of import" section, use the Forward and Backward arrow buttons to specify the point in the directory structure from which you wish to find and import files.

  3. Optionally, select "Import linked pages." When you select this option, additional pages that are linked to the primary page are also imported, as long as they are found within the scope you specify.

  4. Click OK.
The directory structure below the specified point is recreated under the project directory. Only those related files that are found within the specified scope are imported, and these are imported to their proper positions relative to the primary file.

Editing Project Files

You can edit image files and component source files from the Project window in an image or text editor of your choice.

To edit an image, do one of the following:

You can also view or edit JavaScript and .jsb source files directly from the Project window. Do one of the following:

To select your preferred editors in which to edit images and source files, choose Preferences from the Edit menu and select the Editors tab. Set the Image Editor, JavaScript Source Editor, and JSB Source Editor preferences.

See "Using an HTML Editor to Edit Pages" for information on editing HTML files directly.

Editing Pages

In general, you edit pages by dragging components to them from the Component Palette, then setting the properties of the components in the Inspector. You can also insert HTML tags and blocks into a page by choosing options from the Insert menu, or you can drag components or blocks of HTML from other pages.

Tip You can place form elements in an existing form by dropping them onto the form, which is highlighted in blue when the mouse cursor is properly positioned. However, if you drop a form element onto a blank area of a page, a form is automatically created to contain it. §
You can position components on a page by dragging them to new positions. Some components are resizable, as indicated by resize handles around the edges when you select them. To resize a component, click a resize handle and drag it in the desired direction. Some components can only be resized vertically, or horizontally, or in particular increments. The Page Editor automatically resizes in a way that is appropriate to the component.

You can type directly into the Page Editor to add text, then edit and format the text using the toolbar and Format menu. See "Editing Text in the Page Editor." In addition, you can add text into components such as buttons and tables, in various ways. See "Editing Text in Components" and "Editing HTML Tables."

You can add images and links by dragging Image and Link components from the Palette, then editing their properties to specify the reference, or you can drag pages or images to the Page Editor from the Project window. See "Adding Images and Links to Pages."

You can also use another WYSIWYG editor such as Composer to edit your pages, or edit the HTML source directly in a text editor such as Wordpad. See "Using an HTML Editor to Edit Pages."

Editing Text in the Page Editor

You can type text directly into the Page Editor. You can enter text anywhere outside of components, or into the cells of an HTML table. Press Enter (Return) outside any component to create a new line on the page. Press Shift Return to insert a hard line-break in a block of text.

Text that you enter directly into the Page Editor corresponds to blocks of text in the HTML version of the page. You can select a block of text in either the Layout view or Structure view. In the Layout view, you can edit the text directly. When you select a block of text in the Structure view and inspect it, the Inspector displays a multiline text editor in which you can modify the text. (See "Using Custom Component Editors.")

You can select any block of text in either the Layout or Structure view of the Page Editor, and use the Cut, Copy, and Paste commands from the Edit menu, the right-click context menu, or standard Windows keyboard shortcuts (Control-x, Control-c, and Control-v).

You can apply formatting styles to selected text from the style toolbar or the Format menu. Formatting styles include standard HTML heading levels, color, font size and style, bulleted and numbered lists, indentation, right or left justification, and centering.

Editing Text in Components

Text inside components generally corresponds to a property. You can edit the property in the Inspector to enter or change the text.

NOTE: The Name or ID property is the identifier for the component object and does not correspond to any visible text in the component. §

Editing HTML Tables

When you drag an HTML Table component onto a page from the Component Palette, it appears with a default configuration of two rows and two columns. You can edit the table by right-clicking it in the Page Editor and choosing editing options from the context menu. You can:

You can enter or edit text in the cells by typing directly into the Page Editor. When a cell contains text, the text is copied and pasted with the cell. You can also set the absolute size of cells or columns by dragging the edges in the Page Editor.

To specify other aspects of the table's appearance, set the table's properties in the Inspector. For example, to set the size relative to the screen width, instead of to an absolute pixel value, set the Width or Height property to a percentage value, such as 50%.

In the Structure view you can see the HTML tags contained in a table. Rows correspond to the <TR> tag, and cells to the <TD> tag. Notice that columns do not correspond directly to an HTML tag. The Page Editor provides this abstraction for convenience. You can select the HTML tags in the Structure view and edit their properties in the Inspector. You can, for example, set the height or width of an individual cell or row in this way.

The Table Builder

When you insert a table into a page by choosing Table from the Insert menu, the Table Builder appears. Use this dialog box to specify how you want the table to appear before it is placed on the page. When you have finished specifying it, click OK to insert the table into the page. Once it appears on the page, you can modify the table as described in the preceding paragraphs. §

Adding Images and Links to Pages

When you add an Image component to a page from the Component Palette, you must edit the Source property so that it refers to the URL of the image file. You can specify an absolute URL (that is, an address starting with http://), or you can import the image file into the project and simply specify the file name.

If you have imported an image file into the project, you can drag the image icon from the Project window onto a page in the Page Editor. The image appears on the page; that is, an Image component is automatically added to the page with a reference to the image file. (See "Importing Page and Image Files" for more information.)

When you add a Link component to a page from the Component Palette, you must edit the Destination URL property so that it refers to the URL of the page to which you are linking. The URL can be absolute, or it can be relative to the location of the current page (the project directory).

You can drag a page from the Pages list in the Project window onto a page in the Page Editor to create a link to it. A Link component is created and added to the page in the Page Editor, with a reference to the page from the Project window.

Using an HTML Editor to Edit Pages

In addition to the Visual JavaScript Page Editor, you can use an external HTML editor to edit your pages. You can choose to edit pages in any HTML editor; Netscape Composer is the default editor. Provided that you have first installed the latest version of Netscape Communicator 4.0 as indicated in the README.txt file, you can access Composer's formatting capabilities.

Important If you are using Composer, you must use Communicator 4.0 (Composer module) to edit pages or data loss may result. §
To edit a page's source in an HTML layout editor, do one of the following:

If you make changes to a page using an HTML editor and then open the page in the Visual JavaScript Page Editor window (or return the focus to a window where the page is already open), you are prompted to reload the page.

You can also choose to edit the source code for an HTML page directly in a text editor of your choice. To edit the source code for a page, do one of the following:

To select different HTML editors in which to edit your HTML files directly, choose Preferences from the Edit menu and select the Editors tab. Set the HTML Layout Editor preference to select a WYSISWYG editor. Set the HTML Source Editor preference to select a text editor.

Overview of Built-in Components

The components that are provided with Visual JavaScript are described briefly here, and in detail in the Reference section of this book. Right-click a component in the Component Palette and choose What's This from the context menu to display the reference page for that component.

The following tables describe the components that are found by default on each of the default Palette tabs. Since the Component Palette is extensible, you might have additional components and tabs available to you, and new components might be made available in future.

Form Tab

The Form tab contains HTML forms, and standard HTML form input elements such as text fields, check boxes, and buttons. The tab also contains JavaScript form element components that support property and direct connections. (See "Connecting to the Database.")

Note that when you drop a form element component on a page where no form is selected, a form is automatically created to contain the form element.

Table 4.1 The Form tab
Component Definition Language Brief Description
Form

HTML

A standard HTML form: <FORM> HTML tag. (See "Connecting Forms.")

Text Field

HTML

A text entry form input field: <INPUT TYPE=TEXT> HTML tag

Password Field

HTML

A password entry form input field: <INPUT TYPE=PASSWORD> HTML tag

Hidden Field

HTML

A non-visible form element, used to pass information when the form is submitted: <INPUT TYPE=HIDDEN> HTML tag

Multi-line Text Field

HTML

A scrolling, multi-line text entry field: <TEXTAREA> HTML tag

Scrolling List

HTML

A selection list form control: <SELECT> HTML tag. (See "Configuring Selection Components")

Drop-down List

HTML

A drop-down selection list form control, that is, a selection list in which only one option is shown until the user clicks: <SELECT> HTML tag. (See "Configuring Selection Components")

Check Box

HTML

A check box form control: <INPUT TYPE=CHECKBOX> HTML tag

Radio Button

HTML

A radio button form control: <INPUT TYPE=RADIO> HTML tag

Button

HTML

A button form control: <INPUT TYPE=BUTTON> HTML tag

Submit Button

HTML

A special-purpose button that submits the containing form: <INPUT TYPE=SUBMIT> HTML tag

Reset Button

HTML

A special-purpose button that resets the containing form: <INPUT TYPE=RESET> HTML tag

Validated Form

JavaScript

A form that can contain ValidatedText elements, whose values are validated when the user submits the form.

Validated Text Field

JavaScript

A text field element in a ValidatedForm component, whose value can be tested against specified criteria.

JavaScript Select List

JavaScript

A multiple-choice Select list form element that supports property connections. (See "Configuring Selection Components")

JavaScript Radio Group

JavaScript

A radio button group form element that supports property connections.

JavaScript Check Box

JavaScript

A labeled check box form element that supports property connections.

File Upload

HTML

A form element that allows the user to enter or browse for a path and file name: <INPUT TYPE="FILE" SIZE=<x> MAXLENGTH=<y> NAME="<name>"> HTML tag

HTML Tab

The HTML tab contains components made of standard HTML tags or blocks, that are unrelated to forms.

Table 4.2 The HTML tab
Component Definition Language Brief Description
Image

HTML

An image reference: <IMG> HTML tag

HTML Table

HTML

A default HTML table with two columns and two rows: <TABLE> HTML tag, containing two <TR> tags that each contain two <TD> tags

Link

HTML

A hypertext link: <A> HTML tag

Mail-to Link

JavaScript

A link which, when clicked, displays the mail composition window.

Server Label

JavaScript

A text label that can be computed with JavaScript code.

Server Script

HTML

A placeholder for arbitrary Server-side JavaScript code: <SERVER> HTML tag

Client Script

HTML

A placeholder for arbitrary Client-side JavaScript code: <SCRIPT> HTML tag

Database Tab

The Database tab contains JavaScript and Java components that let you connect to specified databases and make use of the LiveWire database functionality. (See "Connecting to the Database.")

Table 4.3 The Database tab
Component Definition Language Brief Description
LiveWire DBPool

JavaScript

A server-side JavaScript component that establishes a database connection.

LiveWire Cursor

JavaScript

A server-side JavaScript component that creates a LiveWire database cursor based on the query defined in the SQL Query property.

JavaScript Client Cursor

JavaScript

A JavaScript cursor component that runs code on both the server and the client. Creates a LiveWire database cursor based on the query specified in the SQL Query property, and constructs a buffer for the result set in client JavaScript.

Java Client Cursor

Java

A client-side Java component that creates a LiveWire database cursor based on the query specified in the SQL Query property.

Simple Server Table

JavaScript

A server-side JavaScript component that creates an HTML table which automatically displays data retrieved by the specified SQL Query, through the specified LiveWire DBPool component. The data is only displayed. You cannot use this component to update data in the database.

Custom Server Table

JavaScript

A server-side JavaScript component that creates a customizable HTML table containing query results when connected to a server-side cursor component through the DataSource property.

Database Form Handler

JavaScript

A server-side JavaScript component that processes a form submission and inserts, updates, or deletes a row in a database table. The component does not appear visually in the end-user interface. (See "Using Forms in Database Applications.")

Database Select List

JavaScript

A server-side JavaScript multiple-choice selection list form element. The contents are generated automatically from data. A connection is established through the specified LiveWire DBPool component. A query is automatically generated from the Table and Filter Column specifications. (See "Configuring Selection Components")

Other Tab

The Other tab contains Java and JavaScript components that are not specifically related to database access.

Table 4.4 The Other tab
Component Definition Language Brief Description
Server Send Mail

JavaScript

A server-side JavaScript component that creates a mail message on the server and sends it. This component is not visible in the end-user interface.

Date Display

JavaScript

A client-side JavaScript component that displays the current date or document last-modified date.

Nervous Text

Java

A client-side Java component that displays text in which the letters "dance". This component supports property connections.

Scrolling Message

JavaScript

A client-side JavaScript component that displays a scrolling message in the Navigator status bar.

Coffee Table

Java

A Java client-side table component that supports direct and property connections. This table can be used to display data from a database, but is also suitable for displaying dynamic data from other sources.

PopChart Lite

Java

A Java client-side graphing component that supports direct and property connections. Creates bar, area, and pie graphs. This component has a custom component editor.

Test Tab

The Test tab contains sample components intended for testing or learning about database access pages. (See "Connecting to the Database.")

Table 4.5 The Other tab
Component Definition Language Brief Description
Java Dummy Cursor

Java

A sample client-side database cursor, intended for demonstration and testing purposes. The component accesses "dummy" data to mimic the behavior of a Java Client Cursor without requiring a server or a database connection.

JS Dummy Cursor

JavaScript

A client-side JavaScript component that displays the current date or document last-modified date.

Java Form

Java

A sample client-side form that supports direct and property connections from client-side cursors.

Choosing Client or Server Components

Some of the components that are included with Visual JavaScript are written in simple HTML code, and others are written in Java or JavaScript. Many components have behavior built into the component, making your task as an application developer easier--you can simply assemble these parts into the program you need. Instead of providing all of the behavior from scratch, you only need to tell the pieces how to talk to each other.

However, when a component includes behavior implemented in Java or JavaScript, that code must run either on the server or on the client. If it runs on the client, the end user must have a Java- or JavaScript-enabled browser.

To give you a full array of choices for your delivery environment, some of the included components provide similar functions but differ in how the functions are implemented. The description of each component in the reference section of this manual includes information about the language used by the component, and also specifies whether it runs on the server or the client. Some components (the JavaScript Client Cursor, for example) have code that runs on both sides.

If you cannot guarantee that the delivery environment will always have a browser with the proper language enabled, choose server-side or HTML components to build your application. If you know that your clients will be using a particular browser, you can take advantage of the additional features that come with client-side Java and JavaScript components.

Editing Components

When you have chosen components and placed them on a page, you can customize their appearance further by editing their properties in the Inspector. For most properties that control the visual appearance, you can simply type in a value or choose from a list of possible values.

Selection components, such as the HTML Scrolling List, are associated with Option objects, which specify the selections in the list. See "Configuring Selection Components" for more information.

You can create a style by setting the visual properties of a component to default values, so that every time you add that component to a page, its visual features are the same. You do this by editing the component in the Component Palette, rather than an instance on a page. See "Creating Default Values for Components" for more information.

Some components that have a complex presentation come with custom editors that are tailored to their special editing needs. When a component has a custom editor, it appears automatically when you inspect the component. See "Using Custom Component Editors" for more information.

In addition to customizing the visual appearance of components, you can specify the behavior of your application by connecting components to one another in various ways, connecting user events to methods or code, and specifying JavaScript and SQL code as property values. For more information, see Chapter 5, "Adding Behavior to an Application."

You can also connect data-display components to data from a database, either directly or through a database cursor. For more information, see Chapter 6, "Developing Database Applications."

Configuring Selection Components

Selection list components that correspond to the <SELECT> HTML tag include two JavaScript components, JavaScript Select Box and Database Select Box, and two versions of a simple HTML component: Drop-down List and Scrolling List.

For any select box, you must specify the list of options to be displayed. Each option has both a display string, which is shown in the selection list, and a value, which is submitted for the selected option when the containing form is submitted. (See "Connecting Forms" for more information on submitting forms.)

The selection option display strings and values are specified differently for the different types of components:

Creating Default Values for Components

You can inspect a component in the Component Palette to see or modify its default property values. Double-click a component in the Palette to bring up the Inspector, or select a component in the Palette to display it in an active Inspector.

When you modify a property value in a Palette component, the value is retained when you drop that component onto a page. Once the component is on a page, you can choose to retain the default values or modify the individual instance.

Using Custom Component Editors

Some components have custom editors that are tailored to their special editing needs. When you inspect such a component, the custom editor appears, either in the Inspector or in a separate window. For example, when you double-click a block of text in the Structure view, the Inspector appears displaying a multi-line text editor. When you inspect a Scrolling List or Drop-down List component, the custom editor allows you to set the list options. (See "Configuring Selection Components.")

To switch between a custom editor and the usual property-display mode of the Inspector, click the buttons at the top of the Inspector window.

If a component includes a custom component editor (called a customizer), the custom editor appears in a separate window, in addition to the Inspector window. An example of this is the custom PopChart editor for the PopChart Lite component. While the custom editor is active, the Inspector is disabled. When the custom editor is in a separate window, you can still use the buttons at the top of the Inspector to switch between the custom editor and the usual property-display mode of the Inspector. When you select Inspector, the Inspector becomes active and the custom editor window disappears. When you select Customizer, the custom editor window reappears, reflecting any changes you made directly to the properties, and the Inspector is once again disabled.

Inspecting Other Objects

In addition to the components, there are a number of other objects in the system that have properties that you can examine or set. You can select and inspect these objects in the Inspector as you can with components.


[Contents] [Previous] [Next] [Last]

Last Updated: 11/06/97 13:24:50


Copyright © 1997 Netscape Communications Corporation