9780764526114 chapter 2 a simple application

Upload: adminharry

Post on 30-May-2018

224 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    1/14

    Lotus Notes and Domino 6 Programming Bibleby Brian Benz, Rocky Oliver and Richard SchwartzWiley Publishing, Inc.. (c) 2003. Copying Prohibited.

    Reprinted for Satyendra K. Jha, [email protected]

    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 inelectronic,paper or other forms without written permission is prohibited.

    http://www.books24x7.com/http://www.books24x7.com/
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    2/14

    Table of ContentsChapter 2: A Simple Application............ ........................................................................................1

    The Purpose of This Example................................................................................................1Creating the Application.........................................................................................................1

    Creating a form................................................................................................................2Creating a view................................................................................................................4Creating a page................................................................................................................6Setting the application's home page................................................................................8Testing the application.....................................................................................................9

    Summary..............................................................................................................................12

    i

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    3/14

    Chapter 2: A Simple ApplicationBy Richard Schwartz

    It's been a tradition for the past twenty years or thereabouts for computer programming books tostart 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 Notesand Domino system administrators. This example is part of the Web site. It's a simple user feedbackmechanism 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'scomments. You return to this application in Chapters 11 and 22 to add security features that preventthis 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. Becausethe links on the page can't be created until after the form and view are created, you're going to buildthe form and view first.

    On TheWeb

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

    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 moredatabase files. You learn more about these files in Chapter 3. Design elements are the basicbuilding blocks of the application, the containers for whatyouseeiswhatyouget (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 NewDatabase dialog box (as shown in Figure 21), and fill in the fields as follows:

    Server: Local

    Title: Ch. 2 Ex. A: User Feedback

    Filename: Ch2AFe edback.nsf

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.wiley.com/compbooks/benzhttp://www.books24x7.com//viewer.asp?bkid=6059&destid=114#114http://www.books24x7.com//viewer.asp?bkid=6059&destid=114#114http://www.books24x7.com//viewer.asp?bkid=6059&destid=60#60http://www.wiley.com/compbooks/benzhttp://www.books24x7.com//viewer.asp?bkid=6059&destid=780#780http://www.books24x7.com//viewer.asp?bkid=6059&destid=388#388
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    4/14

    Figure 21: The New Database dialog boxDomino Designer creates a new file on your PC's hard drive, and displays the Forms index. As youwill 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 apreexisting Domino application, you would see a list of all the forms in the index. Because this is anew application, there are no forms to see yet. You learn a lot more about forms in Chapters 8 and12, but for now the only thing you need to know is that a form is what Domino developers createwhen 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:Click the New Form button. This opens the Form editor. You see Untitled in the window titlebar, and on the Designer's workspace tab, because the new form has not yet been namedand saved. The cursor appears at the top of the form.

    1.

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

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

    3.

    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.

    4.

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

    Name: CommentBody

    Type: Rich Text

    5.

    Lotus Notes and Domino 6 Programming Bible 2

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.books24x7.com//viewer.asp?bkid=6059&destid=252#252http://www.books24x7.com//viewer.asp?bkid=6059&destid=428#428http://www.books24x7.com//viewer.asp?bkid=6059&destid=428#428http://www.books24x7.com//viewer.asp?bkid=6059&destid=252#252http://www.books24x7.com//viewer.asp?bkid=6059&destid=163#163
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    5/14

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

    Close the Field Properties box, click to the right of the placeholder for the CommentBody

    field, and press the Enter key twice.

    6.

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

    Label: Save

    7.

    Click the HideWhen 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 theboxes labeled Previewed for Reading and Opened for Reading. Another check automaticallyappears in the box labeled Printed.

    8.

    Close the Button Properties box.9.

    The pane in the lowerright 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 22. Thenclick the green check that appears at the top of the Programmer's pane. This Notes formulacode instructs Notes to save your data and then close the form's window.

    Figure 22: The Feedback form

    10.

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

    11.

    Lotus Notes and Domino 6 Programming Bible 3

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    6/14

    Creating a view

    On the left side of the Designer workspace, you should see the Bookmark pane, with a rectangularbookmark block representing your application, and an Explorerstyle navigation tree inside theblock. You should see the Feedback form that you just created in the tree. You should also see abranch in the tree labeled Views. Viewsare design elements used to present groups of documentsto a user. Views are also used to allow a user access to a document so that he can work with it; forexample 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. Ofcourse 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:

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

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

    2.

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

    Name: Main

    3.

    Now that you have created a view and given it a more meaningful name, it is time to add somecolumns 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 youcan also enter @functions to compute data to display. Without columns your users wouldn't knowwhat they are looking at. Follow these steps to modify a column in the view:

    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 barrepresents 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 adefault column for this view, and configured it to display an unsorted list of documentsidentified only by simple index numbers that start at one and go up to the number ofdocuments contained in the view.

    1.

    Notice that a list of Simple Functions appears in the Column Value pane on the lower right ofyour 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 whocreated each feedback document.

    2.

    Doubleclick the # symbol to open the Column Properties box. Change fields in the dialogbox as follows:

    Title: User

    Width: 20

    3.

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

    Sort: Ascending

    4.

    Lotus Notes and Domino 6 Programming Bible 4

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    7/14

    Note that the # sign has now been replaced by the word User, and that the rectangular arearepresenting 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 moreuseful. Follow these steps to add a new column to the view:

    Doubleclick in the gray area to the right of the first column to create a second column. Notethat the Column Properties box and the Column Value pane now display information for anew column.

    1.

    Enter the following in the dialog box:

    Title: Date

    Width: 20

    2.

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

    3.

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

    4.

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

    Lotus Notes and Domino 6 Programming Bible 5

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    8/14

    Figure 23: The Main viewCreating a page

    You should now see three tabs running along the top of your Designer workspace. One is labeledCh. 2 Ex. A: User Feedback. Domino Designer keeps one tab open for an index of design elementsin each database that you are working on. If you click this tab, you return to the View index becausethe 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 Chapter16) 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 thepage by using Domino's computed text feature. Follow these steps to create the page:

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

    1.

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

    2.

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

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

    4.

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

    5.

    Choose Create Computed Text from the menu. This inserts the words as a placeholder in the page, and opens the Computed Text Properties box. Close thisdialog box and place your cursor in the Programmer's pane at the lower right of the Designerworkspace.

    6.

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

    7.

    Lotus Notes and Domino 6 Programming Bible 6

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.books24x7.com//viewer.asp?bkid=6059&destid=388#388http://www.books24x7.com//viewer.asp?bkid=6059&destid=428#428http://www.books24x7.com//viewer.asp?bkid=6059&destid=577#577http://www.books24x7.com//viewer.asp?bkid=6059&destid=577#577http://www.books24x7.com//viewer.asp?bkid=6059&destid=388#388
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    9/14

    Figure 24: Computed text on a page

    Click to the right of the placeholder and press Enter twice; then typeClick Here to Submit Feedback.

    8.

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

    9.

    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 moveyour cursor to another place, you'll notice that your text has turned blue.

    10.

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

    11.

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

    12.

    Select Named Element again in the Type field in the dialog box, but this time select Viewfrom 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.

    13.

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

    14.

    Lotus Notes and Domino 6 Programming Bible 7

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    10/14

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

    Figure 25: The Home pageSetting 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'shome page. To do so, follow these steps:

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

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

    2.

    Select Open Designated Page in the When Run in a Browser dropdown list. Anotherdropdown list labeled Page appears. Select Home in the Page dropdown list. Thesesettings are shown in Figure 26.

    3.

    Lotus Notes and Domino 6 Programming Bible 8

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    11/14

    Figure 26: Setting the Launch properties

    Close the Database Properties box.4.

    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 learnabout that in Chapter 6. Instead, this chapter describes how to use Domino Designer's builtin Webpreview server to test your application.

    Only one step is left to prepare for testing. Domino Designer's Web preview server does not knowhow 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 allusers to be anonymous. The default for Domino applications, however, is to disallow anonymousaccess, so this setting must be changed before you use the Web preview server. To do so, followthese steps:

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

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

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

    Close the dialog box.4.

    You're now ready to test the application. If you followed all the directions exactly, the page that youcreated should still be visible on your Domino Designer workspace. (If it isn't, click the Home Pagetab 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 yoursystem. The list also includes the Notes browser, which is installed automatically with your Notes 6client software.

    Select the browser that you want to use for your testing. The application's home page appears inthe browser's window. To complete your test, follow these steps:

    Lotus Notes and Domino 6 Programming Bible 9

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.books24x7.com//viewer.asp?bkid=6059&destid=199#199http://www.books24x7.com//viewer.asp?bkid=6059&destid=199#199
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    12/14

    Click link Click Here to Submit Feedback link. Your Feedback form appears in the browser,as shown in Figure 27.

    Figure 27: Previewing in the browser

    1.

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

    2.

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

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

    4.

    Click the link in the view. A readonly version of the Feedback form appears, and you seethe words you typed earlier.

    5.

    You can also test your application in the Notes client by selecting Design Preview In Notes fromthe menu. The application is shown in the Notes client in Figure 28. The only noncosmeticdifferences that you should notice while testing in the Notes client are as follows:

    Lotus Notes and Domino 6 Programming Bible 10

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    13/14

    Figure 28: Previewing in Notes

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

    Instead of Anonymous, you see your own name listed in the main view because the Notesclient 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 thepage 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 formatknown 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 theform is not very helpful. Also, users have to use the browser's Back button to return to theHome Page. You learn how to provide customized responses and navigation links inChapter 19.

    When run in the browser, the Main view looks ugly. You learn how to customize views inChapter 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 appealthat users expect. You learn how to use colors and graphics to enhance the appearance ofpages and forms in Chapter 12.

    Lotus Notes and Domino 6 Programming Bible 11

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.books24x7.com//viewer.asp?bkid=6059&destid=428#428http://www.books24x7.com//viewer.asp?bkid=6059&destid=694#694http://www.books24x7.com//viewer.asp?bkid=6059&destid=364#364http://www.books24x7.com//viewer.asp?bkid=6059&destid=694#694http://www.books24x7.com//viewer.asp?bkid=6059&destid=539#539http://www.books24x7.com//viewer.asp?bkid=6059&destid=388#388
  • 8/14/2019 9780764526114 Chapter 2 a Simple Application

    14/14

    Summary

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

    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 theFeedback form.

    A Feedback page that contains computed text to display the user's name, along with links tothe 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 willbe a worldclass Domino Developer sprinter. So hang in there, and you'll be building robustapplications in no time at all. Now that you've crawled by building your first application, the nextchapter helps you understand the ground you're covering by explaining the Notes Storage Model.

    Lotus Notes and Domino 6 Programming Bible 12

    Reprinted for [email protected], IBM John Wiley & Sons (US), Wiley Publishing, Inc. (c) 2003, Copying Prohibited

    http://www.books24x7.com//viewer.asp?bkid=6059&destid=60#60http://www.books24x7.com//viewer.asp?bkid=6059&destid=60#60http://www.books24x7.com//viewer.asp?bkid=6059&destid=60#60