MACROMEDIA COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX Getting Started

Summary of COLFUSION MX 7-GETTING STARTED BUILDING COLDFUSION MX

  • Page 1

    Coldfusion ® mx 7 getting started building coldfusion mx applications.

  • Page 2

    Trademarks 1 step robopdf, activeedit, activetest, authorware, blue sky software, blue sky, breeze, breezo, captivate, central, coldfusion, contribute, database explorer, director, dreamweaver, fireworks, flash, flashcast, flashhelp, flash lite, flashpaper, flex, flex builder, fontographer, freehand...

  • Page 3: Contents

    3 contents introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 part i: welcome to coldfusion chapter 1: introducing coldfusion mx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 about coldfusion mx . . . . . . . . . . ...

  • Page 4

    4 contents chapter 5: lesson 2: configuring your development environment . . . . . . . . . 49 exercise 1: verifying the tutorial file structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 exercise 2: setting up your development environment. . . . . . . . . . . . . . . . . . . . . . 50...

  • Page 5

    Contents 5 chapter 11: lesson 8: implementing browsing and searching . . . . . . . . . . . . 123 exercise 1: enabling users to browse trip details . . . . . . . . . . . . . . . . . . . . . . . . . 123 exercise 2: determining actions based on which button a user clicks. . . . . . . . . . 127 exercise...

  • Page 6

    6 contents.

  • Page 7: Introduction

    7 introduction getting started building coldfusion mx applications is intended for anyone who needs to begin programming in the macromedia coldfusion mx 7 development environment. This manual includes a tutorial, which uses supporting files that are installed if you chose to install sample applicati...

  • Page 8

    8 introduction: viewing online documentation all coldfusion mx documentation is available online in html and adobe acrobat portable document format (pdf) files. Go to the documentation home page for coldfusion mx on the macromedia website: www.Macromedia.Com . In addition, you can view the documenta...

  • Page 9: Part I

    Part i welcome to coldfusion part i provides an introduction to macromedia coldfusion mx 7. It defines coldfusion mx 7 and provides an overview of the coldfusion markup language (cfml). It also provides generic database concepts. The following chapters are included in part i: chapter 1: introducing ...

  • Page 11: Chapter 1

    11 chapter 1 introducing coldfusion mx this chapter introduces the core technologies that are the foundation for macromedia coldfusion mx. In addition, it introduces the basic concepts about coldfusion mx, how it works, and the various components that comprise it. Contents about coldfusion mx . . . ...

  • Page 12

    12 chapter 1: introducing coldfusion mx the coldfusion markup language coldfusion markup language (cfml) is a tag-based language similar to html that uses special tags and functions. With cfml, you can enhance your standard html files with database commands, conditional operators, and high-level for...

  • Page 13

    Building applications with cfml 13 building applications with cfml you build coldfusion applications as a series of pages that use cfml. Developers can extend this language by creating their own custom tags or user-defined functions (udf), or by integrating com, c++, and java components, such as jav...

  • Page 14

    14 chapter 1: introducing coldfusion mx.

  • Page 15: Chapter 2

    15 chapter 2 cfml basics this chapter introduces the basic elements of cfml, including how to create macromedia coldfusion pages, and use variables, functions, conditional processing, and form processing. Contents working with coldfusion pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 16

    16 chapter 2: cfml basics the best choice for creating coldfusion pages is macromedia dreamweaver mx. Dreamweaver mx includes many cfml features for building applications, such as rapid visual development, robust cfml editing, and integrated debugging. Dreamweaver mx also includes a copy of homesite...

  • Page 17

    Working with coldfusion pages 17 saving your coldfusion page in order for the coldfusion server to process the page, you must save the coldfusion page on a computer where the coldfusion mx is installed. If you are creating your pages on a local server (on which coldfusion is running), you can save t...

  • Page 18

    18 chapter 2: cfml basics the following figure shows the cfpage.Cfm page in the browser: 2. Do the following tasks: a view the source code that was returned to the browser. In most browsers, you can view the source by right-clicking on the page, and then selecting view source. B compare the browser ...

  • Page 19

    About cfml elements 19 most often the end tag encloses the tag name in brackets and includes a forward slash (/), like this: the information processed by coldfusion is placed between the start and end tag, like this: info to be processed ... Coldfusion tags, for the most part, share these common cha...

  • Page 20

    20 chapter 2: cfml basics functions and number signs you use number signs (#) with functions to display the results of a function on the page. Number signs tell the coldfusion server to evaluate the content between the number signs and display the value, for example: hello world, today’s date is #da...

  • Page 21

    About cfml elements 21 using functions on values usually, a function performs an operation on a value, and the value can include the value of a variable. For example, to format the value of a variable that contains a value in dollars, the code to write this statement might look like this: #dollarfor...

  • Page 22

    22 chapter 2: cfml basics in the following examples, the variables are assigned a string literal value. All string literal values are surrounded by double-quotation marks. In the next example, coldfusion uses the values of the my_first_name and my_last_name variables to set the value for the my_full...

  • Page 23

    Working with cfml expressions 23 displaying variable output output is what remains after the coldfusion server processes the cfml tags on a page. Usually the output has two parts: • information that the user sees (for example, a confirmation message) • information that is stored by the server as a r...

  • Page 24

    24 chapter 2: cfml basics building expressions in coldfusion, you build expressions as you need them. The expressions can include simple elements, such as the expressions shown previously, or they can include complex elements, such as arithmetic functions, strings, and decision operators. (you build...

  • Page 25

    Working with cfml expressions 25 for more information and examples on using number signs in expressions, see coldfusion mx developer’s guide. Specifying quotation marks around values when you assign literal values to variables, you must surround the literal value with single- or double-quotation mar...

  • Page 26

    26 chapter 2: cfml basics the following table lists the unsupported logical operators and their equivalent coldfusion operators: arithmetic operators the following table lists the arithmetic operators that coldfusion supports: unsupported logical operator equivalent coldfusion decision operator desc...

  • Page 27

    About conditional processing 27 string operator the following table describes the one coldfusion string operator that is a concatenation operator: about conditional processing so far, all the coding examples shown in this chapter are considered linear coding examples. Linear codeis when coldfusion e...

  • Page 28

    28 chapter 2: cfml basics using the cfelseif tag to evaluate multiple expressions to evaluate multiple expressions in a cfif statement, you can use cfelseif and cfelse tags in your statement; for example: expression 1> html and cfml tags executed if expression 1 is true. Expression 2> html and cfml ...

  • Page 29

    Processing form data 29 when a user submits a form, the form values are stored in form variables and sent to the action page for processing. The following figure shows the relationship between the form page and action page: in order for the form page to find its corresponding action page, the action...

  • Page 30

    30 chapter 2: cfml basics commenting your code as in other programming languages, it is important to include comments in your code. You should comment your code for the following reasons: • commented code is easier to debug than code that is not commented. • if you describe the code on the page, it ...

  • Page 31: Chapter 3

    31 chapter 3 database fundamentals this chapter provides a quick overview of relational database concepts and terms. It describes what a database is and how it is organized. It also discusses the structured query language (sql) that you use to interact with databases. Contents about database basics....

  • Page 32

    32 chapter 3: database fundamentals what is a relational database? A relational database is a structured collection of information that is related to a particular subject or purpose, such as an inventory database or a human resources database. You use databases to manage information. Information, su...

  • Page 33

    About database basics 33 about relational tables in a database, you can organize data in multiple tables. For example, if you manage a database for the human resources department, you might have one table that lists all the information about employees and another table that lists all the departments...

  • Page 34

    34 chapter 3: database fundamentals about sql sql (structured query language) is a language that lets you communicate with databases. For example, you can use sql to retrieve data from a database, add data to a database, delete or update records in a database, change columns in multiple rows, add co...

  • Page 35

    About sql 35 using the sql where clause to limit the rows returned to conditionally select data from a table, you can add a where clause to the select statement, which results in the following syntax: select column_name from table_name where column condition value with the where clause, you can use ...

  • Page 36

    36 chapter 3: database fundamentals the result of the preceding sql statement contains the following data: note: the preceding sql select examples use single-quotation marks around the value. Sql uses single-quotation marks around text values. Most database systems also accept double- quotation mark...

  • Page 37

    Using sql with coldfusion 37 writing sql and cfml statements to interact with a data source after coldfusion makes a connection to the data source, you can interact with that database by using sql and coldfusion. To interact with an established data source, you must include sql statements in your cf...

  • Page 38

    38 chapter 3: database fundamentals.

  • Page 39: Part II

    Part ii building a coldfusion application part ii provides a tutorial that steps you through building a sample macromedia coldfusion application. It consists of the following lessons: lesson 1: preparing to build the sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

  • Page 41: Chapter 4

    41 chapter 4 lesson 1: preparing to build the sample application this tutorial guides you through the process of building a simple macromedia coldfusion web application. By the end of the tutorial, you will be familiar with how to use macromedia coldfusion mx 7 to query and update a database, valida...

  • Page 42

    42 chapter 4: lesson 1: preparing to build the sample application the following sections explore an overview of each of these application development steps. Exercise 1: determining the application functional requirements before you can build the sample application, you must understand the functional...

  • Page 43

    Exercise 3: designing the database for your application 43 exercise 2: determining the data requirements prior to creating the application pages to capture trip information, you must determine what type of data is required about each trip. For the example in this tutorial, the compass travel trip co...

  • Page 44

    44 chapter 4: lesson 1: preparing to build the sample application if you had to create the compass travel database, you would create a table named trips to store the information that you plan to collect about each trip. The table would look something like the following table: recognizing the data ty...

  • Page 45

    Exercise 3: designing the database for your application 45 establishing a relationship between the two tables when the user selects an event type from the list obtained from reading the eventtypes table, the correct event type must be saved to the trips table with all the other trip-related data. Th...

  • Page 46

    46 chapter 4: lesson 1: preparing to build the sample application exercise 4: developing the sample application using the application functional requirements and the database that is provided for this tutorial, you are ready to use coldfusion to develop the trip maintenance application. The remainin...

  • Page 47

    Exercise 4: developing the sample application 47 • implement browsing and searching ( “lesson 8: implementing browsing and searching” on page 123 ). • enable database maintenance ( “lesson 9: enabling database maintenance” on page 129 ). • restrict access to the compass travel application by requiri...

  • Page 48

    48 chapter 4: lesson 1: preparing to build the sample application you can view coldfusion application pages on your local computer by opening a web browser and entering one of the following urls: for more information about the tutorial file structure and the location of the getting_started subdirect...

  • Page 49: Chapter 5

    49 chapter 5 lesson 2: configuring your development environment in this lesson, you set up your development environment for the tutorial. This lesson describes the tutorial file structure, and how to configure the database connection and debugging options. Additionally, it provides an overview of us...

  • Page 50

    50 chapter 5: lesson 2: configuring your development environment note: when you use the j2ee configuration, the cfdocs directory is under the coldfusion web application root. For more information, see “saving your coldfusion page” on page 17 . Coldfusion mx installs two copies of the sample compasst...

  • Page 51

    Exercise 2: setting up your development environment 51 with dreamweaver mx, you can author and test your application code from a local or remote client. You can save your code directly to the server computer where coldfusion is installed. The following sections provide an overview of dreamweaver mx,...

  • Page 52

    52 chapter 5: lesson 2: configuring your development environment exercise 3: configuring a database connection one of the most commonly used and most powerful features of coldfusion is the ability to connect to and manipulate data from a wide variety of databases. Like most coldfusion developers, yo...

  • Page 53

    Exercise 3: configuring a database connection 53 to access the coldfusion mx 7 administrator: • open a browser and go to one of the following urls: ■ external web server users: http://localhost/cfide/administrator ■ built-in web server users: http://localhost:8500/cfide/administrator ■ j2ee server u...

  • Page 54

    54 chapter 5: lesson 2: configuring your development environment to define the sample pointbase database file: 1. In the coldfusion mx administrator, select data & services > data sources. The add new data source dialog box appears. 2. Specify the following: 3. Click add to configure the data source...

  • Page 55

    Exercise 4: configuring debugging options 55 7. Click verify all connections to ensure that coldfusion can access this file. Ok appears in the status column for successful connections. If the connection to the compass travel data source fails, do the following: a verify that the name of the data sou...

  • Page 56

    56 chapter 5: lesson 2: configuring your development environment the location of the debugging information or the type of debugging data shown varies, depending on the options that you enable on the debugging page in the coldfusion mx administrator. In the following example, the debugging output inc...

  • Page 57

    Summary 57 sending debugging information to remote clients if you are using a remote client to perform the tutorial in this book, you must specify your ip address to receive debugging information. If you are working on a local client (the computer where coldfusion is installed), you do not need to d...

  • Page 58

    58 chapter 5: lesson 2: configuring your development environment.

  • Page 59: Chapter 6

    59 chapter 6 lesson 3: retrieving data in this lesson, you begin the construction of a macromedia coldfusion web application for the fictitious company, compass travel. The exercises in this lesson introduce you to the process of retrieving data from the compass travel relational database. This less...

  • Page 60

    60 chapter 6: lesson 3: retrieving data exercise 1: about the trip list as you recall from “lesson 1: preparing to build the sample application” on page 41 , one of the requirements for the trip maintenance application is the ability to generate trip listings. To help compass travel agents take trip...

  • Page 61

    Exercise 2: retrieving the information for the trip list 61 exercise 2: retrieving the information for the trip list relational database management systems process sql instructions sent to them from various applications. Coldfusion sends sql statements to database managers to manipulate data. Coldfu...

  • Page 62

    62 chapter 6: lesson 3: retrieving data reviewing the code the following table describes the code used to build the query: exercise 3: displaying the query result using the cfoutput tag in chapter 2, “cfml basics,” on page 15 , you learned that the coldfusion cfoutput tag is an easy mechanism to dis...

  • Page 63

    Exercise 4: writing structured, reusable code 63 trip list #tripname# 2. Save the file as triplisting.Cfm in the my_app directory. 3. View the triplisting.Cfm page in a browser. The page lists all the trip names retrieved from the compass travel database. Reviewing the code the following table descr...

  • Page 64

    64 chapter 6: lesson 3: retrieving data to create the cfc file: 1. Create a directory named components as a subdirectory of the my_app directory. 2. Open a new blank file. Note: if you are using dreamweaver, select dynamic page in the category list, and select coldfusion component in the dynamic pag...

  • Page 65

    Exercise 4: writing structured, reusable code 65 copying the query to the cfc to copy the query to the cfc, you copy the cfml to the cfc, between the opening and closing cffunction tags. To copy the query to the cfc: 1. Highlight the following code on the triplisting.Cfm page: select trips.Tripname ...

  • Page 66

    66 chapter 6: lesson 3: retrieving data let dreamweaver do it dreamweaver lets you invoke a method in a cfc without having to write the code. To invoke the method using dreamweaver: 1. Click the components tab in the application panel. 2. Click the + button next to cfdocs.Getting_started.My_app.Comp...

  • Page 67

    Exercise 5: creating additional queries 67 output="false"> select tripname, departuredate, returndate, price from trips where price order by tripname 3. Save the file. Let dreamweaver do it you can use the dreamweaver extensions to create a cfc query and invoke the method that contains the query fro...

  • Page 68

    68 chapter 6: lesson 3: retrieving data invoking the new method to use the new query, you invoke the method that contains the query. To invoke the new method with the enhanced query: 1. Open the triplisting.Cfm file. 2. Modify the following code, or do the steps listed in the “let dreamweaver do it”...

  • Page 69

    Summary 69 3. Save both the triplisting.Cfm file and the gettrips.Cfc file. 4. View the triplisting.Cfm page in a browser and verify that all the new requirements were met. The revised triplisting.Cfm page looks like this: the dates and prices in the preceding listing are not formatted. In “lesson 6...

  • Page 70

    70 chapter 6: lesson 3: retrieving data.

  • Page 71: Chapter 7

    71 chapter 7 lesson 4: building dynamic queries in this lesson, you develop a search form to allow users to select the information to retrieve, and then display, the search results. This lesson contains the following exercises: exercise 1: creating the trip search form . . . . . . . . . . . . . . . ...

  • Page 72

    72 chapter 7: lesson 4: building dynamic queries a better solution is to provide an interface for the user to specify the search criteria. The purpose of the trip search form is to enable compass travel employees to search and view brief details about existing trips on their website. The completed f...

  • Page 73

    Exercise 1: creating the trip search form 73 in later exercises, you will reference these columns when you build the sql select statement for the cfquery in the search action page. Understanding search query operators now that you have decided which columns can be queried (triplocation, departuredat...

  • Page 74

    74 chapter 7: lesson 4: building dynamic queries is begins with is before after is greater than smaller than.

  • Page 75

    Exercise 2: building a query that uses dynamic sql 75 3. Save the file as tripsearchform.Cfm in the my_app directory. Reviewing the code the following table describes the search criteria code and its function: exercise 2: building a query that uses dynamic sql dynamic sql is a term that refers to sq...

  • Page 76

    76 chapter 7: lesson 4: building dynamic queries the action page invokes a method that builds the where clause so that the sql select statement retrieves the information that the user requests. Then, the action page displays an html table with the results of the user query using the cfoutput block. ...

  • Page 77

    Exercise 2: building a query that uses dynamic sql 77 form.Triplocationvalue & "%'" > when you test for a string column within the where clause of the sql select statement, you must enclose the test value in quotation marks. When you use a variable to construct a where clause, you must preserve the ...

  • Page 78

    78 chapter 7: lesson 4: building dynamic queries 4. Add the highlighted code to the cfquery block to use the dynamically built where clause in the query: select tripid, tripname, triplocation, departuredate, returndate, price from trips where #preservesinglequotes(whereclause)# 5. Save the file. Let...

  • Page 79

    Exercise 3: constructing the initial trip search results page 79 exercise 3: constructing the initial trip search results page after the user enters the search criteria and submits the form, the results are posted to the trip search results page, as the following figure shows: the logic contained in...

  • Page 80

    80 chapter 7: lesson 4: building dynamic queries 4. Save the file. Let dreamweaver do it as you have in previous exercises, you can let dreamweaver generate the code to invoke the method. To invoke the method using dreamweaver: 1. Click the components tab. 2. Click the + button next to cfdocs.Gettin...

  • Page 81

    Exercise 4: testing the trip search results page 81 the preceding code only builds the triplocation subclause. In the following exercise, you will add code for the other two columns that you can query, departuredate and price. Exercise 4: testing the trip search results page in this exercise, you wi...

  • Page 82

    82 chapter 7: lesson 4: building dynamic queries 3. Verify that the other criteria (departure date and price) are not taken into consideration yet as follows: a click the back button in the browser to return to the trip search page. B in the departure date drop-down list box, select before, enter 1/...

  • Page 83

    Summary 83 4. To build the price where subclause, enter the following code after the code you entered in the previous step. " & form.Pricevalue> 5. Save the file. Exercise 6: testing the revised trip search results page in this exercise, you will verify that the price and departuredate are now consi...

  • Page 84

    84 chapter 7: lesson 4: building dynamic queries.

  • Page 85: Chapter 8

    85 chapter 8 lesson 5: creating a trip detail page in this lesson you will enhance the compass travel trip maintenance application. This lesson contains the following exercises: exercise 1: creating a trip detail page. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ....

  • Page 86

    86 chapter 8: lesson 5: creating a trip detail page exercise 1: creating a trip detail page by design, the trip search results page displays a subset of the information about a trip. To get additional information about any of the trips, the user should be able to click any row to display the detaile...

  • Page 87

    Exercise 1: creating a trip detail page 87 to build the cfc query: 1. Create a blank coldfusion page. 2. Save the file as tripdetail.Cfm in the my_app directory. 3. Perform the following steps, or do the steps in the “let dreamweaver do it” section. A enter the following code: component="cfdocs.Gett...

  • Page 88

    88 chapter 8: lesson 5: creating a trip detail page 12. In the component location text box, enter /components/. 13. In the recordset name text box, enter tripdetails. 14. In the function text box, enter gettripdetails. 15. In the data source list, select compasstravel. 16. In the table list, select ...

  • Page 89

    Exercise 1: creating a trip detail page 89 3. To provide a title that appears in the browser window, insert the following html code before the line:.

  • Page 90

    90 chapter 8: lesson 5: creating a trip detail page 4. Add the following code at the end of the file: 5. Save the file. To view the trip detail page: 1. Open a browser. 2. Enter one of the following urls, which use the tripid of 24, which specifies the rio cahabon rafting trip: http://localhost/cfdo...

  • Page 91

    Exercise 2: avoiding the potential security risk when using dynamic sql 91 reviewing the code the following table describes the coldfusion code that you use to build the trip detail page: as you did in this exercise, you can build comprehensive database query applications using cfml and dynamic sql....

  • Page 92

    92 chapter 8: lesson 5: creating a trip detail page if a user called the trip detail page using the following statement: http://localhost/cfdocs/getting_started/my_app/tripdetail.Cfm?Id=24;drop+trips the sql database management system executes the proper sql select statement, and then immediately er...

  • Page 93

    Exercise 4: enhancing the look of the trip search results and trip detail pages 93 to test the revised page: 1. View the tripsearchform.Cfm page from the my_app directory in your browser. 2. In the trip location drop-down list, select begins with, and enter the value c. 3. Click search. The trip sea...

  • Page 94

    94 chapter 8: lesson 5: creating a trip detail page 2. Save the file. 3. To format the currency and date fields on the trips search results page, open the tripsearchresult.Cfm file in your editor and make the changes for departuredate , returndate , and price indicated in the table. 4. Save the file...

  • Page 95

    Summary 95 summary in this lesson, you transformed the search facility that you built in “lesson 4: building dynamic queries” into a drill-down facility for trip queries. You built a trip detail page to show more information about a particular trip. You also formatted the trip search results and tri...

  • Page 96

    96 chapter 8: lesson 5: creating a trip detail page.

  • Page 97: Chapter 9

    97 chapter 9 lesson 6: creating a main application page in this lesson you will enhance the compass travel trip maintenance application. So far, you created a very useful drill-down query facility. Compass travel trip coordinators can produce lists required by management and easily locate and displa...

  • Page 98

    98 chapter 9: lesson 6: creating a main application page exercise 1: creating the main application page from the trip detail page in this exercise, you convert the trip detail page into the main trip maintenance application page. The main application page includes additional buttons for navigating t...

  • Page 99

    Exercise 1: creating the main application page from the trip detail page 99 to add navigation buttons to the trip detail page: 1. Open the tripdetail.Cfm file in the my_app directory. 2. Insert the following code between the and tags: note: the current trip record id ( tripid ) is in a hidden field ...

  • Page 100

    100 chapter 9: lesson 6: creating a main application page reviewing the code the following table describes the navigation code for the trip detail page: exercise 2: adding database maintenance buttons the search and sequential navigation capabilities are features for locating compass travel trips. A...

  • Page 101

    Summary 101 to test the updated application: 1. Open your browser. 2. Enter the following url to view the updated tripdetail.Cfm page http://localhost/cfdocs/getting_started/my_app/tripdetail.Cfm?Id=8 note: if you are using the built-in coldfusion server, enter localhost:8500 instead of localhost . ...

  • Page 102

    102 chapter 9: lesson 6: creating a main application page.

  • Page 103: Chapter 10

    103 chapter 10 lesson 7: validating data to enforce business rules in this lesson, you will create a page for the trip coordinator to add new trip offerings and update existing trips. In addition, you will add logic to validate that data entered so that it complies with compass travel business rules...

  • Page 104

    104 chapter 10: lesson 7: validating data to enforce business rules exercise 1: using an html form to collect data in this exercise, you develop the trip edit page, which provides a data entry form that is used to add new trips and edit existing trips. You validate the data entered against compass t...

  • Page 105

    Exercise 1: using an html form to collect data 105 surfing mountain climbing mountain biking.

  • Page 106

    106 chapter 10: lesson 7: validating data to enforce business rules 3. Save the file as tripedit.Cfm in the my_app directory. Reviewing the code the following table explains the use of some of the html tags in the trip edit page. For more information on html, consult any html primer. To test the tri...

  • Page 107

    Exercise 2: creating a simple action page 107 at this point, this form does not store any information in the database and does not enforce any business rules of compass travel. In the next exercise, you develop the action page to enforce the business rules. Exercise 2: creating a simple action page ...

  • Page 108

    108 chapter 10: lesson 7: validating data to enforce business rules exercise 3: about data validation to ensure that the data entered in the trip edit form is valid, compass travel has identified a set of business rules for capturing and editing trip information. A fundamental concern is ensuring th...

  • Page 109

    Exercise 4: providing server-side validation 109 exercise 4: providing server-side validation in this exercise, you will learn about the following tasks: • creating a local variable to indicate whether data entered in the form conforms to the compass travel business rules • ensuring that a value was...

  • Page 110

    110 chapter 10: lesson 7: validating data to enforce business rules because you did not yet add any logic to test whether any values entered in the form are valid, the page works precisely as before, displaying a message that indicates the database was updated, without actually performing the update...

  • Page 111

    Exercise 4: providing server-side validation 111 evaluating check box and radio button variables business rule 8 in the compass travel new trip policy requires you to test the value of the depositrequired check box form variable. Check box and radio button variables are only passed to the action pag...

  • Page 112

    112 chapter 10: lesson 7: validating data to enforce business rules note: you have already entered validation code for business rule 1. Validation code for business rule 10 is described in more detail later in this lesson. Rule description validation code 2 all trips must be accompanied by a full de...

  • Page 113

    Exercise 4: providing server-side validation 113 note: the code for business rules 7 and 8 uses coldfusion cfif and cfelse conditional processing tags. The code inside the cfif tags only executes when the condition evaluates to true. To perform other actions when the condition evaluates to false, th...

  • Page 114

    114 chapter 10: lesson 7: validating data to enforce business rules to test the validation code: 1. View the tripedit.Cfm page in the browser. 2. In the form, enter 500 in both the price and base costfields. 3. Click the save button. The trip price error message displays: "price must be marked up at...

  • Page 115

    Exercise 5: validating data on the client using coldfusion form tags 115 coldfusion form tags include the following attributes: to use the improved form tags, you must replace the html form tag with the cfform tag. The following code snippets show the use of the improved coldfusion form tags. The fi...

  • Page 116

    116 chapter 10: lesson 7: validating data to enforce business rules modifying the trip edit page to use coldfusion form tags in this exercise, you use the coldfusion form tags to move the validation of many business rules from the server to the client. To do this, you change the html form tags in th...

  • Page 117

    Exercise 5: validating data on the client using coldfusion form tags 117 tip: for additional help, review the completed code in the ttripedit_lesson7_ex5.Cfm file within the solutions directory. For more details about using coldfusion form tags and their attributes, see coldfusion mx developer’s gui...

  • Page 118

    118 chapter 10: lesson 7: validating data to enforce business rules 5. Open the tripeditaction.Cfm file in the my_app directory and delete the code for the following single-field validation rules: ■ trip name is required. ■ trip description is required. ■ trip leader is required. ■ photo filename is...

  • Page 119

    Exercise 6: dynamically populating the list of event types 119 to test the modified code: 1. View the tripedit.Cfm page in a browser. 2. Test the client- and server-side field validations by filling out the fields on the form and clicking save. Testing recommendations: ■ omit required fields such as...

  • Page 120

    120 chapter 10: lesson 7: validating data to enforce business rules 4. Replace the following eventtypes code lines: message="type of event must be selected."> surfing mountain climbing mountain biking message="type of event must be selected."> surfing mountain climbing mountain biking with these lin...

  • Page 121

    Exercise 7: validating the existence of the trip photo file 121 for more information about the fileexists function, see cfml reference. To verify that the photo filename exists: 1. Open the tripeditaction.Cfm file in the my_app directory. 2. Add logic to check that the user entered a valid photo fil...

  • Page 122

    122 chapter 10: lesson 7: validating data to enforce business rules reviewing the code the following table describes the code used to verify whether the photo file exists: summary as described in this lesson, coldfusion offers a number of alternatives to validating data. If you are familiar with sta...

  • Page 123: Chapter 11

    123 chapter 11 lesson 8: implementing browsing and searching in this lesson, you will further enhance the compass travel macromedia coldfusion application by providing code to implement the navigation and searching functions. This lesson contains the following exercises: exercise 1: enabling users t...

  • Page 124

    124 chapter 11: lesson 8: implementing browsing and searching using dynamic sql to browse the trips table the tripid uniquely identifies a trip in the trips table. In “lesson 6: creating a main application page” on page 97 , you displayed the trip detail page for a trip by passing the id as a parame...

  • Page 125

    Exercise 1: enabling users to browse trip details 125 limiting the number of result rows each of the sql statements in the preceding table returns a result set of trips rows. The result set can range from zero to any number of rows. The navigation action page must limit the result set count to 1, be...

  • Page 126

    126 chapter 11: lesson 8: implementing browsing and searching reviewing the code the following table describes the code used to process the navigation button requests: to test the navigation: 1. View the tripdetail.Cfm page from the my_app directory in a browser. 2. Click the next row button. The tr...

  • Page 127

    Exercise 3: enabling searching from the trip detail page 127 exercise 2: determining actions based on which button a user clicks in “lesson 6: creating a main application page” on page 97 , you added buttons to the trip detail page to let users search and modify the trips database; however, because ...

  • Page 128

    128 chapter 11: lesson 8: implementing browsing and searching reviewing the code the following table describes the code that executes when the user clicks the search button: summary in this lesson, you added the capability of browsing trips sequentially to the trip detail page. You also limited the ...

  • Page 129: Chapter 12

    129 chapter 12 lesson 9: enabling database maintenance in this lesson, you will enable maintenance of the trips database. The exercises will guide you through the steps of adding the database update logic to delete trips, add new trip offerings, and update existing trips in the compass travel databa...

  • Page 130

    130 chapter 12: lesson 9: enabling database maintenance the sql delete statement removes existing rows in a relational table. The delete statement has the following format: delete from table_namewhere column_name = some_value for example, the database table named clients contains holds information a...

  • Page 131

    Exercise 2: adding trips with sql insert statements 131 to test the delete capability: 1. View the tripdetail.Cfm page in a browser. The current trip is nepal. Notice that the destination for the nepal summit challengetrip is imji himal, nepal. 2. Click search. The trip search page appears. 3. In th...

  • Page 132

    132 chapter 12: lesson 9: enabling database maintenance for example, the database table named clients contains information about people in the following rows: to add a record to the table, use the following statement: insert into clients values ('smith', 'kaleigh', '14 greenway', 'windham') after th...

  • Page 133

    Exercise 2: adding trips with sql insert statements 133 to add data using a sql insert statement and a cfquery tag: 1. Open the tripeditaction.Cfm file in the my_app directory. 2. Locate the tag near the end of the file. After the line, add the following code in the following table to insert the dat...

  • Page 134

    134 chapter 12: lesson 9: enabling database maintenance to test the modified code: 1. Open the tripedit.Cfm page in your browser. 2. In the tripedit.Cfm page, enter in the fields the values in the following table, and then click save. After the new trip is written to the database, the following mess...

  • Page 135

    Exercise 3: adding data using the cfinsert tag 135 reviewing the code the following table describes the sql insert and cfquery code that coldfusion uses to add data: for more information about adding data to a database using sql and the cfquery tag, see coldfusion mx developer’s guide. For more info...

  • Page 136

    136 chapter 12: lesson 9: enabling database maintenance to add data using cfinsert: 1. Open the tripeditaction.Cfm file from the my_app directory in your editor. 2. Remove the entire addtrip cfquery code block that you added in exercise 2: adding trips with sql insert statements : insert into trips ...

  • Page 137

    Exercise 4: updating a sql row using the cfupdate tag 137 3. To verify that the trip was saved, open the tripsearchform.Cfm page in the my_app directory in your browser. 4. In the trip search page, in the trip location drop-down list, select the begins with option, and enter the value nor in the tex...

  • Page 138

    138 chapter 12: lesson 9: enabling database maintenance reviewing the code the following tables describes the cfinsert and cfupdate code: to update the database using a cfupdate tag: 1. Open the tripeditaction.Cfm file in the my_app directory in your editor. 2. Add the following code before the tag ...

  • Page 139

    Exercise 6: inserting values in the edit form 139 3. Insert the highlighted code: 4. Save the file. Exercise 6: inserting values in the edit form notice that when the user clicks the add button, the maintenanceaction.Cfm page navigates to the tripedit.Cfm page without passing any arguments. Converse...

  • Page 140

    140 chapter 12: lesson 9: enabling database maintenance 3. To make the appropriate values appear in the form, insert the code that is highlighted in the following table: note: if the user clicks the add button, the values from the currently displayed trip detail appear in the form; otherwise, all va...

  • Page 141

    Exercise 6: inserting values in the edit form 141 size="10" required="yes" validate="date" value="#departuredate#" message="departure date must be a valid date."> set the value of the departure date to be blank if the id is undefined; otherwise, set the value equal to the departure date that appeare...

  • Page 142

    142 chapter 12: lesson 9: enabling database maintenance reviewing the code the following table describes the code that coldfusion uses to properly initialize the trip edit form: to test the modified code: 1. Open the tripdetail.Cfm page in your browser. 2. Do the following tasks: a click the edit bu...

  • Page 143: Chapter 13

    143 chapter 13 lesson 10: restricting access to coldfusion applications this chapter provides information on using the login wizard to restrict access to a new or existing macromedia coldfusion application. You will learn about the login wizard, and then add user authentication to the compass travel...

  • Page 144

    144 chapter 13: lesson 10: restricting access to coldfusion applications preparing to run the login wizard before using the login wizard, you should determine the following information: • which of the authentication types you want to use to restrict access to your application. The types include the ...

  • Page 145

    Exercise 1: about the login wizard 145 adding user authentication to an existing application you can use the login wizard to add user authentication to an existing application. The login wizard modifies the existing application.Cfc. If your application uses an application.Cfm file instead of an appl...

  • Page 146

    146 chapter 13: lesson 10: restricting access to coldfusion applications creating a login using simple authentication when you create a login using simple authentication, you specify one username and password that all users enter to gain access to your application. To create a login using simple aut...

  • Page 147

    Exercise 2: requiring users to log in to the compass travel application 147 creating a login using windows nt authentication 1. Start the login wizard. (see “starting the login wizard” on page 145 .) 2. Select nt as the type of authentication. 3. Select one of the following: basic authentication to ...

  • Page 148

    148 chapter 13: lesson 10: restricting access to coldfusion applications to test the authentication: 1. Open the tripdetail.Cfm page in the my_app directory in your browser. 2. When prompted, enter compassstaff as the user name. 3. Enter columbus92 as the password. Summary in this lesson, you learne...

  • Page 149: Index

    149 index a action pages creating 107 defined 28 actions based on buttons 127 adding database maintenance buttons 100 navigation buttons 98 rows to a table 131 and operator 75 answers in solution files 47 application. See tutorial authentication about 143 ldap 146 simple 146 windows nt 147 b browsin...

  • Page 150

    150 index conditional processing 27, 28, 76, 82 contains operator 73 context root 17 creating action pages 107 cfcs 64 cross-field edits 108 currency, formatting 93 d data sources defined 36 supported 13 data types, recognizing 44 data validation about 108 client-side 115 server-side 109 data, retri...

  • Page 151

    Index 151 g greater than operator 73 h html forms 73 i inserting, values in forms 139 invoking methods 65, 68 isdefined function 85 j j2ee configuration 17 l ldap authentication 146 ldap server 143 less than operator 73 limiting, number of rows 125 linking, buttons and actions 127 lists, dynamically...

  • Page 152

    152 index sql and operator 75 commands 34 data source 36 described 34, 37 dynamic 75, 124 insert statement 131 order by statement 36 security risks 91 select statement 34, 61 using 61 where clause 35 writing statements 37 starts with operator 73 structured code 63 t tags attributes 19 cfform 103 cfi...