Sei sulla pagina 1di 14

Lotus Notes and Domino 6 Programming Bible

by Brian Benz, Rocky Oliver and Richard Schwartz


Wiley Publishing, Inc.. (c) 2003. Copying Prohibited.

Reprinted for Satyendra K. Jha, IBM


satyejha@in.ibm.com

Reprinted with permission as a subscription benefit of Books24x7,


http://www.books24x7.com/

All rights reserved. Reproduction and/or distribution in whole or in part in


electronic,paper or other forms without written permission is prohibited.
i

Table of Contents
Chapter 2: A Simple Application....................................................................................................1
The Purpose of This Example................................................................................................1
Creating the Application.........................................................................................................1
Creating a form................................................................................................................2
Creating a view................................................................................................................4
Creating a page................................................................................................................6
Setting the application's home page................................................................................8
Testing the application.....................................................................................................9
Summary..............................................................................................................................12
Chapter 2: A Simple Application
By Richard Schwartz

It's been a tradition for the past twenty years or thereabouts for computer programming books to
start with an example called Hello, World. The example code simply displays the text "Hello, World"
on the user's screen. In this chapter we pay a bit of homage to that tradition, but we don't really stick
to its spirit. Our first example application does a little bit more than just say "Hello".

The Purpose of This Example


In this book, most of the examples are either part of a sample Web site or part of a toolkit for Notes
and Domino system administrators. This example is part of the Web site. It's a simple user feedback
mechanism for the site, and it has the following features:

• It says "Hello" to the user.

• It displays the user's name.

• It enables the user to enter a comment.

• It allows users to see comments posted by all users.

Note that a real Web site feedback application would probably not allow users to see each other's
comments. You return to this application in Chapters 11 and 22 to add security features that prevent
this while still allowing site administrators to see all comments.

The application consists of one form, one view, and one page. Users open the application to the
page, which contains links to the form and view. Users use the form to enter their own comments.
They use the view to see an index of all the comments that have been entered thus far. Because
the links on the page can't be created until after the form and view are created, you're going to build
the form and view first.

On The This example can be downloaded from www.wiley.com/compbooks/benz.


Web

Creating the Application


To create an application from scratch, the first thing you must do is start Domino Designer. After
that, you create a database file and add some design elements. All applications use one or more
database files. You learn more about these files in Chapter 3. Design elements are the basic
building blocks of the application, the containers for what−you−see−is−what−you−get (WYSIWYG)
designs and code. You learn more about design elements in Chapter 4, and throughout the book.

To create the application's database file, choose File → Database → New to open the New
Database dialog box (as shown in Figure 2−1), and fill in the fields as follows:

Server: Local

Title: Ch. 2 Ex. A: User Feedback

Filename: Ch2−A−Fe edback.nsf

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 2

Figure 2−1: The New Database dialog box


Domino Designer creates a new file on your PC's hard drive, and displays the Forms index. As you
will learn in Chapter 5, Domino Designer presents indexes of the different types of design elements
(forms, views, pages, and so on) that make up an application. If you were working with a
pre−existing Domino application, you would see a list of all the forms in the index. Because this is a
new application, there are no forms to see yet. You learn a lot more about forms in Chapters 8 and
12, but for now the only thing you need to know is that a form is what Domino developers create
when they want to allow users to enter data.

Creating a form
Follow these steps to create a form in Domino Designer and add text and fields to it:

1. Click the New Form button. This opens the Form editor. You see Untitled in the window title
bar, and on the Designer's workspace tab, because the new form has not yet been named
and saved. The cursor appears at the top of the form.

2. Type User Feedback at the top of the form and press the Enter key twice.

3. Using your mouse, go to the top of the form and select the text that you just entered (User
Feedback), being careful not to select the two empty lines that you created below it. Click
the B icon on the toolbar to change the text to boldface.

4. Position the cursor at the second of the two empty lines below the title (User Feedback).
Type Enter your comments here and press Enter twice.

5. Choose Create → Field from the menu. Designer inserts a field element in the form where
your cursor is positioned with a placeholder title of Untitled, along with the Field Properties
box. Change the following items in the dialog box:

Name: CommentBody

Type: Rich Text

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 3

Note Whenever you are instructed to modify parameters of a properties box in this chapter
it is presented in the preceding fashion, which is property name: value. So in this
instance the Name property should be set to CommentBody, and the Type property
should be set to Rich Text.

6. Close the Field Properties box, click to the right of the placeholder for the CommentBody
field, and press the Enter key twice.

7. Choose Create → Hotspot → Button from the menu. Designer inserts a standard button in
the form and then displays the Button Properties box. Change the following item in the
dialog box:

Label: Save

8. Click the Hide−When tab in the Button Properties box. (This is the third tab from the right,
with an icon that looks like a horizontal line with a small loop under it.) Put checks in the
boxes labeled Previewed for Reading and Opened for Reading. Another check automatically
appears in the box labeled Printed.

9. Close the Button Properties box.

10. The pane in the lower−right of the Designer workspace is known as the Programmer's pane.
Click in that pane to place your cursor there, and type
@Command([FileSave]);@Command([FileCloseWindow]) as shown in Figure 2−2. Then
click the green check that appears at the top of the Programmer's pane. This Notes formula
code instructs Notes to save your data and then close the form's window.

Figure 2−2: The Feedback form

11. Choose File → Save from the menu. The Save Form As dialog box opens. Type Feedback
into the dialog box and click OK. You now see Feedback listed in the Forms index.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 4

Creating a view
On the left side of the Designer workspace, you should see the Bookmark pane, with a rectangular
bookmark block representing your application, and an Explorer−style navigation tree inside the
block. You should see the Feedback form that you just created in the tree. You should also see a
branch in the tree labeled Views. Views are design elements used to present groups of documents
to a user. Views are also used to allow a user access to a document so that he can work with it; for
example a user might want to open it, edit it, or delete it. All databases are required to have at least
one view, which is why there is always one view — Untitled — in every database you create. Of
course this view is either modified to be usable or deleted (because you create your own views)
during the development of your application. Follow these steps to create a view for this application:

1. Click the Views entry in the tree. The Views index appears.

2. Domino always provides a default view for every application, which appears in the index as
"(untitled)". Double−click it to open it in the View editor and bring up the View Properties box.

3. Fill in the name property in the dialog box as follows:

Name: Main

Now that you have created a view and given it a more meaningful name, it is time to add some
columns to the view to make it usable for your users.

Modifying a column

Columns in a view present individual item values from the documents displayed in a view, or you
can also enter @functions to compute data to display. Without columns your users wouldn't know
what they are looking at. Follow these steps to modify a column in the view:

1. Close the View Properties box and click the pound symbol (#) that appears inside the
rectangular section of the gray bar at the top of the View design pane. The gray bar
represents the column header that appears at the top of a view displayed in Notes client.
The rectangular area of the bar represents a column in the view. Domino Designer created a
default column for this view, and configured it to display an unsorted list of documents
identified only by simple index numbers that start at one and go up to the number of
documents contained in the view.

2. Notice that a list of Simple Functions appears in the Column Value pane on the lower right of
your Designer window. Change the selection in this window from # in view to Author(s)
(Simple Name). This selection causes Domino to display the name of the person who
created each feedback document.

3. Double−click the # symbol to open the Column Properties box. Change fields in the dialog
box as follows:

Title: User

Width: 20

4. Click the Sorting tab in the dialog box (it looks like a pair of arrows with one pointing up, and
the other pointing down). Change fields in the dialog box as follows:

Sort: Ascending

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 5

Note that the # sign has now been replaced by the word User, and that the rectangular area
representing the column has grown and is highlighted to indicate that it is currently selected.

Adding a new column

You have modified the existing column in your view — now you are beginning to build a view that is
useful to your users. The next step is to add additional columns to your view to make it even more
useful. Follow these steps to add a new column to the view:

1. Double−click in the gray area to the right of the first column to create a second column. Note
that the Column Properties box and the Column Value pane now display information for a
new column.

2. Enter the following in the dialog box:

Title: Date

Width: 20

3. Close the Column Properties box, and then change the Simple Function selection in the
Column Values pane to Creation Date. This selection causes Domino to display the date
that each feedback document was created.

4. Choose File → Save from the menu. Be sure to click Yes when you are asked whether you
want to save your changes.

The view, which is now complete, is shown in Figure 2−3. Notice that the entry for (Untitled) in the
View index has been updated and now says Main.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 6

Figure 2−3: The Main view


Creating a page
You should now see three tabs running along the top of your Designer workspace. One is labeled
Ch. 2 Ex. A: User Feedback. Domino Designer keeps one tab open for an index of design elements
in each database that you are working on. If you click this tab, you return to the View index because
the most recent type of element you created was a view. The other tabs are labeled Feedback −
Form and Main − View. These represent the design elements that you have created so far.

You can tie these design elements together into a complete application in many ways. You could,
for example, use a frameset and an outline (see Chapter 11) to provide links to the form and view.
Or, you could set the application to launch directly into the view and add a View action (see Chapter
16) that opens the form. Instead, however, you're going to have the application launch into a page,
and put links to the form and view on that page. You're also going to display the user's name on the
page by using Domino's computed text feature. Follow these steps to create the page:

1. Click the Pages branch of the navigation tree in the Bookmark pane. This opens the Pages
index. As was the case with the Forms index, this will be empty because it's a new
application.

2. Click the New Page button. This creates an empty page in the Designer workspace. Pages
are similar to forms. You learn all about them in Chapter 8. For now, the most important
thing to know is that the Domino Page editor lets you use WYSIWYG techniques to lay out
text, graphics, and links for a page that can be viewed in the Notes client or a browser.

3. Type User Feedback at the top of the page and press the Enter key twice.

4. Using your mouse, go to the top of the page and select the text that you just entered (User
Feedback), being careful not to select the two empty lines that you created below it. Click
the B icon on the toolbar to change the text to boldface.

5. Position the cursor at second of the two empty lines below the title (User Feedback). Type
Hello and press Enter twice.

6. Choose Create → Computed Text from the menu. This inserts the words <computed value>
as a placeholder in the page, and opens the Computed Text Properties box. Close this
dialog box and place your cursor in the Programmer's pane at the lower right of the Designer
workspace.

7. Type @UserName in the Programmer's pane and click the green check box at the top of the
Programmer's pane. Figure 2−4 shows the computed text formula you just entered.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 7

Figure 2−4: Computed text on a page

8. Click to the right of the <computed value> placeholder and press Enter twice; then type
Click Here to Submit Feedback.

9. Select the text you just created with your mouse, and then choose Create → Hotspot → Link
Hotspot from the menu. The Hotspot Resource Link Properties box opens. You will create a
link from this page to the Feedback form you created earlier.

10. In the dialog box, locate the Type field and select Named Element from the selection list.
Another selection control appears immediately to the right. Select Form from this second list.
Also, type Feedback in the Value field of the dialog box. Close the dialog box. If you move
your cursor to another place, you'll notice that your text has turned blue.

11. Position your cursor at the end of the text and press Enter twice; then type Click Here to
View Feedback.

12. Select the text you just created with your mouse, and then choose Create → Hotspot → Link
Hotspot from the menu to display the Hotspot Resource Link Properties box again. You are
about to create a link to the Main view you created earlier, just like you did with the
Feedback form.

13. Select Named Element again in the Type field in the dialog box, but this time select View
from the second list and type Main in the Value field of the dialog box. Close the dialog box.
Notice that the new text has also turned blue.

14. Choose File → Save from the menu. The Save Page As dialog box opens. Type Home into
the dialog box and click OK.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 8

The finished page, with the Hotspot Properties box still open, is shown in Figure 2−5.

Figure 2−5: The Home page


Setting the application's home page
The last thing you need to do is tell Domino to use the page you just created as the application's
home page. To do so, follow these steps:

1. Choose File → Database → Properties from the menu. The Database Properties box opens.

2. Click the Launch tab. (This is the third tab from the right, with an icon that resembles a
rocket ship tilted on a 45 degree angle.)

3. Select Open Designated Page in the When Run in a Browser drop−down list. Another
drop−down list labeled Page appears. Select Home in the Page drop−down list. These
settings are shown in Figure 2−6.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 9

Figure 2−6: Setting the Launch properties

4. Close the Database Properties box.

Testing the application


After all the design elements are done, you must test and deploy an application to a Web server.
Because this is just a simple sample the actual deployment isn't described in this chapter. You learn
about that in Chapter 6. Instead, this chapter describes how to use Domino Designer's built−in Web
preview server to test your application.

Only one step is left to prepare for testing. Domino Designer's Web preview server does not know
how to prompt users for a login name and password, but it does enforce Domino's rules that control
who can use an application. Without a login prompt, however, the Web preview server considers all
users to be anonymous. The default for Domino applications, however, is to disallow anonymous
access, so this setting must be changed before you use the Web preview server. To do so, follow
these steps:

1. Choose File → Database → Access Control. The Access Control List dialog box opens.

2. Select Default in the large listing window in the dialog box.

3. Select Author in the Access field on the right of the dialog box.

4. Close the dialog box.

You're now ready to test the application. If you followed all the directions exactly, the page that you
created should still be visible on your Domino Designer workspace. (If it isn't, click the Home − Page
tab at the top of the workspace, or click Home in the Bookmark pane to bring it up.) Choose Design
→ Preview in Browser from the menu. You see a submenu listing the browsers available on your
system. The list also includes the Notes browser, which is installed automatically with your Notes 6
client software.

Select the browser that you want to use for your testing. The application's home page appears in
the browser's window. To complete your test, follow these steps:
Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 10

1. Click link Click Here to Submit Feedback link. Your Feedback form appears in the browser,
as shown in Figure 2−7.

Figure 2−7: Previewing in the browser

2. Type a few words in the field that appears on the form, and then click the Save button. The
words Form processed appear.

3. Click your browser's Back button twice to return to the application's home page.

4. Click link Click Here to View Feedback link. The application's main view appears. It's not
pretty, but it is functional. You should see one entry in the view, with an Anonymous link.

5. Click the link in the view. A read−only version of the Feedback form appears, and you see
the words you typed earlier.

You can also test your application in the Notes client by selecting Design → Preview In Notes from
the menu. The application is shown in the Notes client in Figure 2−8. The only noncosmetic
differences that you should notice while testing in the Notes client are as follows:

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 11

Figure 2−8: Previewing in Notes

• Form processed does not appear after you click the Save button. Instead, you automatically
return to the application's home page.

• Instead of Anonymous, you see your own name listed in the main view because the Notes
client knows your identity.

Improving This Sample

This sample application is functional, but basic. Here are some ways to improve it:

• When run directly from the Notes client (rather than being previewed), the Home Page does
not appear. To launch a page in the Notes client, you must create a frameset and put the
page into it. You learn how to do this in Chapter 11.

• When run in the Notes client, your name appears on the Home Page in an ugly format
known as the canonical form fully distinguished name. You can clean this up by using the
@Name function, which you learn about in Chapter 15.

• When run in the browser, the Form Processed feedback provided when the user submits the
form is not very helpful. Also, users have to use the browser's Back button to return to the
Home Page. You learn how to provide customized responses and navigation links in
Chapter 19.

• When run in the browser, the Main view looks ugly. You learn how to customize views in
Chapter 10, and you learn to use view templates to improve their appearance in Chapter 19.

• Whether you run it in the Notes client or a browser, the application lacks the visual appeal
that users expect. You learn how to use colors and graphics to enhance the appearance of
pages and forms in Chapter 12.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited
Lotus Notes and Domino 6 Programming Bible 12

Summary
In this chapter, you saw that it's possible to create a simple application consisting of three design
elements:

• A Feedback form with some static text, a modifiable field, and a button.

• A Feedback view that lists the author and creation date of documents created with the
Feedback form.

• A Feedback page that contains computed text to display the user's name, along with links to
the form and view.

While this seems overly simplistic, you do need to crawl before you walk. This was a "crawling"
chapter. Later in this book you get your legs under you and begin walking, and by the end you will
be a world−class Domino Developer sprinter. So hang in there, and you'll be building robust
applications in no time at all. Now that you've crawled by building your first application, the next
chapter helps you understand the ground you're covering by explaining the Notes Storage Model.

Reprinted for ibmsatyejha@in.ibm.com, IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

Potrebbero piacerti anche