This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Table of Contents Topic 1: Browser Objects and JavaScript................................................................9 Topic 2: Coding JavaScript in Domino Designer ..................................................25 Topic 3: Basic Language Elements........................................................................55 Topic 4: Branching and Looping Structures..........................................................71 Topic 5: Custom Functions....................................................................................83 Topic 6: JavaScript Objects ...................................................................................93 Topic 7: Arrays ....................................................................................................123 Topic 8: Browser Object Model ..........................................................................143 Topic 9: Browser Event Handlers........................................................................165 Topic 10: Field Access.........................................................................................181 Topic 11: Field Input Translation and Validation................................................203 Topic 12: Form Validation...................................................................................223 Topic 13: Window Object....................................................................................239 Topic 14: Frame Object .......................................................................................263 Topic 15: Location Object ...................................................................................273 Topic 16: Browser State Persistence....................................................................297 Topic 17: Dynamic HTML ..................................................................................321 Topic 18: JavaScript and Java Applets ................................................................341 Topic 19: Domino Views.....................................................................................365 Topic 20: JavaScript and ActiveX Controls ........................................................375 Topic 21: Asynchronous JavaScript and XML....................................................383 Topic 22: Browser Compatibility ........................................................................399 Topic 23: JavaScript Resources ...........................................................................417 Index ....................................................................................................................425
Domino Designer 8: JavaScript
3
Description During this course you will use Domino Designer 8 to add JavaScript to Domino applications that are accessed by browsers. The course covers the basic language elements of JavaScript, how to add scripts using Domino Designer, and how to exploit the various browser and language object event handlers. There is a strong emphasis on the browser object model and how it relates to the Domino object model. The course also touches on how to incorporate Dynamic HTML, Java Applets, LiveConnect, ActiveX controls, and AJAX into web-based applications.
Course goals This course will: •
build a fundamental knowledge of JavaScript as it is applied in Domino applications used by modern browsers
•
provide practical programming and debugging experience to ensure a foundation of JavaScript skills
•
understand the relationship between JavaScript and Domino data types
•
clarify the use of the various object models, including the Domino Object Model, the original browser Document Object Model, JavaScript language objects, and the newer W3C Level 1 Document Object Model
•
use JavaScript to code the Field, Button, and Form event handlers
•
build a practical understanding of data validation and error trapping
•
use DHTML to create interactive web pages
•
control Java applets using LiveConnect
•
remotely access Domino objects via CORBA
•
script ActiveX objects
•
use AJAX to request and process Domino-generated XML
•
develop practical ways to detect which browser is being used and how to code appropriately.
4
Domino Designer 8: JavaScript
Audience This course assumes that you have: •
thorough knowledge of the Domino Designer 8 development environment, including Form, Page, View, Frameset, and Agent design, as well as how to set properties and set the ACL
•
knowledge of web technologies, including servers, browsers, HTML, Cascading Style Sheets, and some basic JavaScript (or other browser scripting language) and awareness of browser object properties and methods
•
basic understanding of LotusScript and the various Notes product objects
•
because this course does not review any aspects of the non-JavaScript aspects of developing applications with Domino Designer, mastery of the topics covered in these courses: •
This course is part of a series of Domino Designer 8 training courses. Follow these paths to master all aspects of developing applications using Domino Designer: Clients
Notes 8 Experience
Lotus Notes 8 User Essentials NCUE8 - 1 day
Basic Notes Applications DDBNA8 - 4 days
Special Notes Features DDSNF8 - 2 days
Basic Browser Applications DDBBA8 - 1 day
DB2 for Domino 8 Administrators and Developers DB2D8 - 2 days
Languages
Formula Language DDFL8 - 2 days
LotusScript DDLS8 - 4 days
JavaScript DDJS8 - 3 days Web Agents and Web Services DDWAWS8 - 2 days
Domino Designer 8: JavaScript
5
Domino Designer 8: Basic Notes Applications provides the base knowledge for this additional training: Client Track •
Configure Domino to use DB2 as a database engine and build applications that access relational data, DB2 for Domino 8 Administrators and Developers.
•
Specialize in programming Notes applications to respond to built-in user interface features, Domino Designer 8: Special Notes Features.
•
Convert an application written for Notes clients to be used in browsers, Domino Designer 8: Basic Browser Applications.
•
Provide data to cutting-edge web applications, Domino Designer 8: Web Agents and Web Services.
Language Track. These languages apply to both Notes and browser clients: •
Learn sophisticated application techniques that fully exploit the formula language in Domino Designer 8: Formula Language.
•
Develop sophisticated applications and Agents with LotusScript in Domino Designer 8: LotusScript.
•
Add powerful client-side scripting to browser applications in Domino Designer 8: JavaScript.
Course design The course takes a task-oriented approach, during which you will work with JavaScript code that will have immediate application to your Domino applications. Because this course instructs you how JavaScript works with respect to Domino, you will be able to leverage the many JavaScript resources available to you as a developer.
6
Domino Designer 8: JavaScript
Data files To ready your computer and the Domino Server for the course, you must run the INSTALL.EXE program from the class diskette on the computer running Domino Designer. Specify the default Notes \Data directory during the installation; if you put it into a subdirectory outside the \Data directory, the examples will fail. By default, a subdirectory named \Data\DDJS8 is created for you. The DDJS8 Demo (DDJS8DEMO.NSF) database is installed. It is used to demonstrate all the code used in the course and as the starting point for the exercises. During the first exercise you will create your own non-replica copy of the DDJS8 Demo database on the Domino Server, where you will complete the exercises. There are also a number of other resource files that will be installed to your local drive (sample ActiveX controls and Java Applets) that you will use during the course. All exercises must be performed from your copy of the database running on the Domino Server and tested from there. You should have Domino Designer 8 and Internet Explorer 7+ installed on your computer (IE will run all the example code). You should also install Mozilla Firefox 2+ to test cross-browser compatibility. Be sure you have access to Domino Designer 8 Help, which should be full text indexed. Please consult the Set Up document for this course to make sure the correct environment is in place before starting the course.
Conventions This course follows these font conventions: •
Italic - database, view, form, document, macro, and field names, as well as object event handlers
•
Bold - menu options, command button names, and accelerator keys, function/statement names (for clarity)
•
Courier- user input, sample values, code examples, constants
'' is two single apostrophes together, not a double quote mark. Domino Designer 8: JavaScript
7
Notes
8
Domino Designer 8: JavaScript
Topic 1: Browser Objects and JavaScript Key points This Topic provides a historical and conceptual background of how JavaScript relates to and interacts with browsers. It also describes how Domino Server dynamically and securely serves pages containing JavaScript to browsers.
Preview of the Domino/browser exchange This diagram illustrates the exchange between Domino and a browser (you will learn more about all the pieces in the following sections): Domino Server
File System
NSF
Web Server
HTTP Browser
This table describes the exchange between Domino and a browser: Stage 1
Description A browser requests a URL that is on the Domino server. In this example, the URL opens a Form in which the user will add values to several fields and will save the results back as a document in the NSF on the server. Pretty simple stuff.
2
Domino pulls the necessary resources from the NSF, in this example, a Form.
Topic 1: Browser Objects and JavaScript
9
Stage 3
Description The Form itself is designed in Domino Designer and Domino is responsible for converting various design elements into HTML: • Fields are converted to HTML tags. • The Save button that is designed to run @Command([FileSave]); @Command([FileCloseWindow]) is
converted to JavaScript that submits the document back to the server when clicked. • The Form may also have text that has embedded HTML tags (including inline <SCRIPT> tags) and has been marked as Passthru HTML, so Domino doesn’t need to do any conversion. • The Form may have “passthru” elements, where code was added in Domino Designer in various browser-specific places, such as: • HTML Head Content. Added to the HTML page tag (uses the Function language to dynamically define content). • JS Header. JavaScript added to a <SCRIPT> block in the page . • OnLoad. JavaScript added to the tag onLoad event handler. • If the Form calls an Agent in its WebQueryOpen event, the code (written in LotusScript or Java) is executed (often used to programmatically set default field values). After all the computations are performed (regardless of the original incarnation of any element), the Form is converted entirely to browser-compatible HTML and sent down to the browser via HTTP.
10
Topic 1: Browser Objects and JavaScript
Stage 4
Description The browser renders the elements of the HTML page. In this example, the Form has an tag pointing to a .JPG in the \HTML directory on the Domino server, so as the browser renders the page, it fetches the image. You can think of the page as having a visual aspect, what the user sees, and code. Some of the code was run before the visual pieces were rendered (like the code in the onLoad event), but other client-side code isn’t executed until the user takes some action, like clicking a button. The point to be made here is that all “stuff” of the visual aspects and client-side code buried in the HTML page has been shipped down to the browser from Domino, and it is now up to the browser to deal with it. What this means for the developer is that you must deeply understand at least these two things: • How Domino converts (or passes through) things you add in Domino Designer. • What the browser does with page once it arrives (including whether or not the browser is capable of processing the page).
5
In this example, the user clicks the Save button and the page is submitted back to Domino. With respect to the Save button, as the Form developer you not only had to add all the things necessary for the page to render and operate properly in the browser, you also had to anticipate what happens when the user is done with the page. In this case you added an image of a Save button that when clicked submits the Form back to the server. A Form may also have a Cancel button, or a Go Back to the View button; a View may have a Next Page button to show the next 20 documents in the View, or a New Document button. So now because you also have to anticipate user navigation away from the page, you now have three things about the Form you must worry about.
Topic 1: Browser Objects and JavaScript
11
Stage 6
Description Domino receives the page from the browser and is now responsible for transforming its information into a document in the database. To do this, Domino fetches the original Form to interpret the field data. It runs the field formulas (computed, input translation, input validation). If there are input validation failures, Domino sends an error page back to the browser. If the Form calls an Agent in its WebQuerySave event, the code (written in LotusScript or Java) is executed (often used to more gracefully handle field validation errors or to redirect the user to another place in the application after successfully writing the document to the database).
7
Once all the conditions and code of the original Form have been met, the document is created in the database.
8
Depending on what you code to happen next, Domino can return something back to the browser, like an error or confirmation message, back to the Form for error correction, or to the next logical place in the application.
Programming challenge Programming Domino applications for browsers is really quite a challenge. As you saw above, there are several opportunities to apply code: •
Server-side code that runs before the HTML page is shipped down to the browser.
•
Client-side code that runs entirely in the browser and eventually is responsible for posting something (usually the HTML form) back to the server.
•
Server-side code that processes the response from the browser.
12
Topic 1: Browser Objects and JavaScript
In this course, the emphasis is on the client-side code, specifically how JavaScript can be used to manipulate browser and Document Object Model (DOM) objects created by tags included in the current HTML page and by JavaScript language itself: Browser Object Model
+
(DOM Level 0)
Browser
Client-side Scripting Document Object Model (DOM Level 1)
Domino Server
HTML
Server-side Scripting
+
+
Cascading Style Sheets
Domino Object Model
This course also necessarily must also deal somewhat with Domino as the Web Server, so you also will work with the Domino Object Model and how to use: •
@Functions to create Views as well as to code buttons and Action buttons using a subset of @Functions (the code is automatically converted to JavaScript by Domino).
•
LotusScript (and/or Java) for powerful server-side processing such as to dynamically create HTML pages or perform post-submit processing.
The history of client-side scripting In the beginning, the idea of a web browser was to display crudely formatted text and images using a simple markup language (HTML) and provide hyperlinks to other pages. It only took a few years for this simple display-only approach to change drastically to where the browser is now a universal user interface for custom applications. Scripting in browsers is implemented as a runtime interpreted language that cannot run outside the context of an HTML page interpreted by a browser. This is because the code is actually sent in human-readable text along with the HTML content to the browser for local execution. The browser renders the HTML it finds and executes the script from various events. JavaScript has its own development history parallel to but separate from browsers. It should really be thought of as independent from the browser object model because there are browsers that support other scripting languages (e.g. Perl, Java, Python, etc.) and because JavaScript is also used in non-browser products (e.g. Windows Script Host, Groove, etc.).
Topic 1: Browser Objects and JavaScript
13
For simplicity, this course focuses on “JavaScript” as a generic label for the various scripting language variants used in the most popular browsers: •
JavaScript is the scripting language used to script browsers with a Netscape lineage (AOL stopped supporting the Netscape browser in March 2008), such as the newer Mozilla/Gecko-based browsers.
•
Microsoft Internet Explorer uses JScript (as well as VBScript), a JavaScript variant that is COM-aware.
•
ECMAScript (the European Computer Manufacturers Association's ECMA262 language) comes from the Web Standards Project, and is an attempt to standardize the native language elements and language-based objects of browser scripting. Both Microsoft and Mozilla-based browsers claim to be ECMAScript compatible, though each adds extensions that the other cannot interpret. Mozilla, for example, follows as much as possible the ECMAScript standard.
JavaScript is a somewhat full-featured scripting language with variables of several data types, various math, string, equivalence, and Boolean operators, statements, functions, arrays, error trapping, objects, and object events/methods/properties, giving it the ability to perform computations and interact with users via dialog boxes. The JavaScript language objects are used to manipulate data, which may/may not be derived from browser objects: JavaScript language objects
Array Boolean Date
Enumerator Event Function
Math Number Object
RegExp Screen String
Not wanting to be limited to the language primitives, open source and commercial vendors continue to stretch the utility and power of JavaScript: •
New pre-built JavaScript libraries are continually being released (such as Dojo, Prototype, and JQuery), making it easier and faster to develop interactive applications that use AJAX.
•
Popular web sites like Google and Yahoo provide interfaces for services that you can include on your pages and control with JavaScript.
14
Topic 1: Browser Objects and JavaScript
Brief history of browser object models Using JavaScript to code browser behaviors has always been challenging because of the rapid development cycle of browsers. With each browser brand (Internet Explorer, Mozilla-based browsers, Safari, etc.) and version comes a new and improved object model. Because you generally can't control which browser brand or version is installed on users' computers, your code has to either find a lowest common denominator or branch to accommodate the many possible browser brand/version combinations. You’ll learn more about browser compatibility late in this course. When JavaScript was first introduced to browsers, the first object model was the Browser Object Model, now known as the Document Object Model (DOM) Level 0. The early browsers Netscape Navigator 2 and Internet Explorer 3 supported the Level 0 DOM. As browsers developed, Microsoft and Netscape developed competing and incompatible proprietary DOMs in their Version 4 browsers to support Dynamic HTML and Cascading Style Sheets. It would be convenient (but alas impossible) to ignore these models because the differences are both significant and aggravating. While IE continues to support most of its first DOM in its current version, Netscape completely abandoned its version 4 DOM and has replaced it starting with Netscape 6 with the W3C DOM. When Netscape development transferred to the open source Mozilla Organization in 1998, the Mozilla browser continued with implementing the W3C DOM. These are the standards-based, vendor-neutral models promoted by the W3C (http://www.w3.org/DOM/, summarized nicely at http://www.mozilla.org/docs/dom/reference/levels.html): •
DOM Level 1 incorporates and extends Level 0 as well as provides full support for Dynamic HTML (DHTML). Level 1 is supported to some extent by most current "5th generation" browsers such as Netscape 6+ and Internet Explorer 5+ (as well a bevy of standards-based browsers such as Mozilla Firefox and Opera). This is considered the current DOM.
•
In 2000, DOM Level 2 added a style sheet object model for easier access to styles attached to a document. It also introduced an event model and support for XML namespaces. The 5th generation browsers (e.g. Mozilla) support some aspects of DOM Level 2, but not all.
•
In 2004, the W3C published the latest specification for DOM Level 3. (http://www.w3.org/TR/DOM-Level-3-Core). It extends DOM Level 2 primarily to enhance support for XML/XHTML.
Topic 1: Browser Objects and JavaScript
15
Even with standards to follow, it is left up to the browser vendors to implement the standards as they see fit, which in practice means spotty support and proprietary extensions (go to http://www.w3.org/2003/02/06-dom-support.html to see what DOM modules your favorite browser supports). It is also up to web page developers to code their pages to work with both current and past browsers. Note: The bulk of this course is based on DOM Level 0 and then turns to DOM Level 1 in a later Topic that discusses Dynamic HTML (DHTML).
Launch browser from Lotus Notes Which browser Notes launches when you hit a URL found in a Notes document (including a message) depends on User Preferences: •
Notes 8 Standard configuration. Notes uses the browser that is set as the default browser in the operating system. The choice you have in Preferences is whether to launch that browser in a Notes window tab or in its own window outside of Notes.
•
Notes 8 Basic configuration and previous versions of Notes. The current Location document determines which browser opens, and you have more choices than with the Standard configuration. You can choose any browser to launch in an outside window, or in the case of the “Notes browser” or IE (“Notes with Internet Explorer”), open it in a Notes window tab. FYI, the “Notes browser” is the least standards-compliant browser you can pick (it is uses an early Mozilla/4.0 rendering engine that uses ECMAScript 1.4, though it lacks a complete browser DOM, as you will see below) but is tied into the Personal Web Navigator 6.0 application, which has some minor advantages). We won’t even attempt to code for the Notes browser in this course. Fortunately “Notes with Internet Explorer” is the default and best browser to use.
Don’t confuse the browser launched by Notes to render web pages with the Notes rendering engine used to display Notes documents. The Notes rendering engine itself supports some of the DOM objects and a limited range of JavaScript.
16
Topic 1: Browser Objects and JavaScript
Browser Object Model (DOM Level 0) Virtually everything in a browser environment as well as the content on an HTML page is considered an object, with its associated events, properties, and methods. The shaded boxes in the browser DOM represent browser objects, while the unshaded boxes represent HTML objects that are created using HTML tags: navigator
window
location
frame
document
history
image
link
form
anchor
applet
button reset submit
checkbox radio select
text textarea hidden password
fileupload
submit reset
toolbar, etc.
area
How does this relate to what a user sees on a web page? This diagram shows the relationship between the HTML that makes up a web page and the nested hierarchy of objects: Navigator Window Document (HTML page)
The Navigator object represents the browser itself. The Window object contains the Document object, which in turn contains elements, including one or more Form objects, each containing one or more Element objects.
Topic 1: Browser Objects and JavaScript
17
JavaScript vis-a-vis browser objects JavaScript has access to the methods and properties of browser objects. Although the various browsers differ slightly in their object models, there is a large common base of language, browser, and HTML objects that they all share. The whole idea behind JavaScript is to create interactive web pages that don't require a round trip to the server for server-side code execution. An equally important goal for dual-client applications is to provide equivalent features and experience for both audiences. With its ability to work with these language, browser, and HTML objects, using JavaScript you can: •
automate navigation
•
dynamically generate HTML content
•
change the location and format of text and graphics using Dynamic HTML (the combination of HTML, Cascading Style Sheets, and JavaScript)
•
show Field-level help in the browser status bar or a popup window as they hover over links
•
prompt users for information using built-in alert, confirm, and prompt dialog boxes or through simulated @DialogBox or @Picklists with data fed from Notes documents or Views
•
perform simple Field translation and validation interactively at the browser without refreshing the Form, which requires a round-trip and a page refresh (Domino runs the Field Input Translation and Validation formulas and returns a new page showing the results)
•
change Form open behavior by calling a JavaScript function in the onload browser event handler; the Form submit behavior can be changed by calling a function in the Submit event handler
•
create or destroy windows (such as to simulate custom dialog boxes)
•
dynamically update window and Frame locations and content
•
store user preferences in cookies on the local computer for later recall or passed as part of URL links for page pre-processing based on the preferences.
All of this is possible because JavaScript has full access to browser objects.
18
Topic 1: Browser Objects and JavaScript
Note: Again, because Lotus Notes also supports JavaScript (though with fewer browser objects), the goal for the developer is to write applications that work for both browsers and Notes without recoding. In practice, you will find this possible for very basic things only, since Notes just doesn't completely support all the browser objects.
Mozilla’s DOM and JavaScript object Inspector Want to know everything there is to know about the DOM and JavaScript objects on a web page? Open the page in the DOM Inspector that comes with Mozilla Firefox or Netscape Browser 8+. How you open the tool varies by browser. In Firefox, it is Tools - DOM Inspector. In the left pane, you can navigate the DOM nodes and see the object details in the right pane:
You can switch to view Stylesheets or JavaScript Object properties. We think this tool is immensely helpful in understanding both the DOM and JavaScript object hierarchies. As the course progresses you will be working with all three types of objects (DOM, Stylesheet, JavaScript).
Topic 1: Browser Objects and JavaScript
19
Domino as a Web server Domino Designer is what you use to create design elements that combine HTML and JavaScript, but it is the Domino Server that is responsible for serving the pages to browsers. Domino is made up of a core executable and a number of add-in tasks to fulfill various functions, such as database access, replication, mail routing, etc. Together, these tasks contribute to the list of Domino Services and Objects, as shown in this diagram: Domino Server Domino Services and Objects (directory, security, replication, mail, DECS, etc.)
APIs Protocols
Notes RPC
NRPC
Web Server
HTTP
Corba
IIOP
Mail & Directory
POP IMAP SMTP LDAP
Domino provides client access via various protocols to various APIs. Browsers access the Domino services and objects through the Domino Web Server using the HTTP protocol.
The Domino "Web Server" The Domino "Web Server" is made up of the Application Server and the HTTP engine. This diagram shows the relationship between the server components and the URL parsing performed by the HTTP server: Domino "Web Server" Domino Web Application Server
.nsf in URL
.html CGI/PERL
Domino HTTP Engine
HTTP w/ or w/o SSL V3, X.509
TCP/IP Network
Browser
20
Topic 1: Browser Objects and JavaScript
Domino Databases (.NSF)
•
•
HTTP Server. The native Domino HTTP server task is much like a typical HTTP server, in that it parses URL requests from browsers and interprets/returns pages (which contain HTML and client-side scripts) or refers calls to other interpreters (CGI/PERL) or servers (such as to streaming video servers). In addition to HTTP services, Domino also includes: •
user authentication from the Domino Directory, X.509 certificates, or LDAP referrals
•
connection, server request, and cookie logging
•
URL mapping and redirection
•
authentication realms, single sign-on (between Domino Servers and between Domino and Websphere) and session-based authentication (you can create custom forms to enter name and password)
•
HTML file protection
•
Internet Cluster Manager for load balancing and failover
•
Domino Web Server API filters (DSAPI)
•
ability to run Java Servlets.
Application Server. If the URL includes ".nsf", the commands appended to the URL (such as ?OpenForm) are passed to the application server for processing. The application server generates pages on-the-fly using the logic coded in the application and returns standard HTML back to the HTTP server to deliver to the browser. The server also responds to: •
Web Services requests (over HTTP) and packages responses in SOAP.
•
Requests for View data to be returned to the browser as XML or JSON (in response to the ?ReadViewEntries URL command).
Keep in mind that the HTTP server task and the application server both use the same Domino databases; as such, your applications, if designed correctly, can service both Notes clients as well as browser clients.
Topic 1: Browser Objects and JavaScript
21
Third-party Web server plug-ins There are two ways to look at integrating the Domino Web Server with other web server products: •
It can plug into third-party web servers such as Microsoft IIS (the first certified server) and IBM HTTP Server (IHS) (more in the future). Whereas the third-party web server handles static pages and other resources (ASP, JSP, CGI, etc.), calls to .NSF databases are passed to the Domino Web Server, even if the two servers are separated by a firewall (third-party web server sits in the DMZ while Domino sits inside the firewall).
•
More third-party plug-ins can run under the Domino Web Server due to its extended DSAPI support. The IBM WebSphere Application Server's servlet engine (J2EE application server), for example, can plug into the Domino Web Server (this actually started with Domino 5.0.5 but has been enhanced with each revision). The benefit—in addition to running servlets—is that WebSphere can use the Domino Directory for authentication via LDAP and users can sign on once to either Domino or WebSphere and their authentication credentials are carried between the servers.
Exercise: Create project databases In this exercise you will install the example/exercise database and other resource files on your local hard drive and then create a non-replica copy of your example/exercise database on the classroom server. Step
Action
1
Instructor will tell you to find the course data installer (INSTALL.EXE).
2
Run the installer so that the files are copied to your local hard drive in a folder under your Notes \Data directory. The files are saved to the local \Data\DDJS8 folder.
3
The Instructor has registered you as a Domino user and has given you the right to create new databases on the classroom server. The instructor will provide your Notes user name, Notes User ID password, and Internet Password (is set to be the same as your Notes password).
22
Topic 1: Browser Objects and JavaScript
Step 4
Action Follow these steps to create a new non-replica copy of the DDJS8 Demo database on the Domino Server that you will use in all the exercises: • Start Lotus Notes. • Choose File – Application – Open and browse to the local folder containing the DDJS8 Demo database. Open the database. • With the database open, choose File – Application - New Copy. • Specify the classroom server name given by the Instructor as the location for the new database. • Change the file name to a unique name, perhaps including your initials, such as JJBExercises.NSF. • Enter a title that you will remember, such as JOE's Exercise Database. Note: In all exercises, this database will be referred to as Your Exercises database. Where you see this name, substitute your database name. • Deselect Access Control List, as you want yourself and the Domino Server to be listed as Managers in the ACL. • Leave all the other settings at their defaults. • Click OK to create the database (again, you have been given rights to create a new database on this Server).
5
If not open already, open the Your Exercises database on the classroom server.
6
Choose File - Application - Access Control. For now, click the -Default- setting and select Author access. Also select the can create and delete documents rights. Click OK to save the settings.
Topic 1: Browser Objects and JavaScript
23
Step
Action
7
Switch to your browser to test the ability of Domino to find the Your Exercises database. Enter this URL to create a Discussion document: http://server/jjbExercises.nsf/discussion?openform
Be sure to substitute the server and directory/database names so that you open your copy of the database to the Discussion Form. If the Form opens, you are successful and are ready to continue.
8
24
When everyone has finished creating their database on the server, the Instructor will use Domino Administrator to sign all the databases using the Instructor ID. (There are a couple of Agents that need signing before they will run on the classroom server.)
Topic 1: Browser Objects and JavaScript
Topic 2: Coding JavaScript in Domino Designer Key points This Topic looks at how to code HTML and JavaScript in various design elements using Domino Designer. It also explains how Domino Server interprets the design you create and renders pages containing HTML and JavaScript.
HTML page structure The Domino Designer development environment integrates HTML and JavaScript so that the code you write is properly translated and placed in the proper context on the HTML page when sent to the browser as well as to Notes. Domino builds HTML forms on-the-fly using the Form design as its set of instructions. It outputs fairly generic HTML, taking care to make the necessary conversions to produce a reasonable facsimile of the original design. To facilitate talking about how Domino interprets a Form and converts it to HTML sent to the browser, let's look at a simple Form, DesignToHTML Form, from the DDJS8 Demo database:
Here is what the Form looks like rendered in a browser:
Topic 2: Coding JavaScript in Domino Designer
25
Here is the HTML source sent down from Domino, as viewed by the browser. This is everything the browser has to work with--the HTML to display the page and the JavaScript to make it interactive (line numbers were added for this discussion): 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 26
DesignToHTML Test Form <script language="JavaScript" type="text/javascript"> <script language="JavaScript" type="text/javascript">
49. 50. 51. 52. 53.
54. 55. 56.
57. 58. 59. 60. 61. 62.
// -->
This page sent to the browser from Domino contains all the HTML and JavaScript the browser needs to work with the Form, including a button to submit the form back to the server. Even though the HTML page is sent as a whole, the job of programming the various elements is done in many places within Domino Designer. This diagram shows just one instance of how the JS Header event ends up being placed in the section of the HTML page:
Topic 2: Coding JavaScript in Domino Designer
27
This table shows where the work is done in Domino Designer, identifying the relevant line numbers (if present) from where everything ends up in the source HTML source shown above: Line # 1-3 4 n/a
5
HTML Source
Designer Location
Domino adds the DOCTYPE, HTML, and HEAD tags automatically.
Server Generated
The Window Title event formula determines the <TITLE> placed in the
Window Title event
Additional tags in the , such as <META> tags including keywords or document refresh information, link information, language, or other information that defines the document, can be defined here using @Functions.
$$HTMLHead Field or HTML Head Content
Demarcate the part of the HTML that the language interpreter should pay attention to.
Server Generated
While most browsers assume that <SCRIPT> (without the language argument) is JavaScript, it is a good idea to specify the language in the event the file is interpreted by a browser that can process other or multiple languages. 6, 22
It is a good idea to include the comment symbols () to hide the code from browsers that don't support or have disabled JavaScript. To these browsers, this is just commented HTML. Compliant browsers can read the code with no problem. The "//" is added as a JavaScript comment so that the browser doesn't try to evaluate the "-->", which would result in an error. You will learn more about browser compatibility in a later Topic.
28
Topic 2: Coding JavaScript in Domino Designer
Server Generated
Line # 7-21
HTML Source
Designer Location
JavaScript functions entered into the block of the HTML page. Putting them here makes them globally available throughout the document and can be called from other windows or frames by referencing the container document as the source of the code.
JS Header event
Also note that any variables declared in the are global to all other JavaScript on the page. Note: Though grouped together with the other JavaScript events in Domino Designer (shown with circles in the Object Browser), the JS Header is NOT a browser object event handler, but rather a place to write JavaScript functions that will be placed in the section of the page. 2450
JavaScript functions generated by the Domino Server to handle the actions taken by buttons and Actions written using the Function Language. You cannot modify or delete this code.
Server Generated
Note: The Database property Web access: Use JavaScript when generating pages must be set (this is the preferred setting when coding for the web) for this to happen. 52
Used primarily to set various attributes such as the colors of the background, text, links, visited links.