iw3htp3_27

horseheadssolidInternet και Εφαρμογές Web

10 Νοε 2013 (πριν από 3 χρόνια και 1 μήνα)

93 εμφανίσεις



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

Chapter 27


Macromedia

ColdFusion MX

Outline

27.1

Introduction

27.2

Simple ColdFusion Example: Clock

27.3

Using Variables and Expressions

27.4

Variable Scoping

27.5

Form Processing

27.6

Creating a Data Source Name

27.7

Bookstore Case Study: Interface and Database

27.8

Bookstore Case Study: Shopping Cart

27.9

Advanced Topics for ColdFusion Developers

27.10

Web Resources



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

Objectives


In this lesson, you will learn:


To create basic ColdFusion templates.


To use ColdFusion Markup Language tags and functions to
add dynamic functionality to Web pages.


To use information collected from Web forms.


To create a database
-
driven bookstore application.


To create a shopping cart for the bookstore that follows a
user through the site.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.1

Introduction



ColdFusion


Widely used server
-
side markup language


Developed by Allaire


ColdFusion Markup Language (CFML)


Based around a set of tags that work like XHTML tags


Supports XML, ColdFusion Components and Web services


Saved with a
.cfm

extension


ColdFusion template



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.2

Simple ColdFusion Example: Clock



CFML comment


<!
---

CFML Comment
---
>


cfoutput

tag


Variables and functions are enclosed in
#
’s


dateFormat


timeFormat


now



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

clock.cfm

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.1 : clock.cfm
---
>

6
<!
---
A simple ColdFusion example
---
>

7

8
<!
--
-
CFML comment tag
---
>

9
<!
--
XHTML comment tag
--
>

10

11
<html xmlns =
"http://www.w3.org/1999/xhtml"
>

12

<head>

13

<title>
A Simple ColdFusion Example
</title>

14

15

<style type =
"text/css"
>

16

p

{

fon
t
-
size
:

14pt
;

color
:
blue
}

17

td

{

background
-
color
:

black
;

color
:

yellow

}

18

</style>

19

</head>

20

21

<body>

22

23

<p>
A Simple ColdFusion Example
</p>

24

25

<table border =
"1"
>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

clock.cfm

(2 of 2)

26

<tr>

27

<td>

28

29

<!
---
#’s between cfoutput tags are processed
---
>

30

<!
---
Display the current date
---
>

31

<cfoutput>
#
dateFormat( now(),
"mmmm dd, yyyy"
)
#
</cfoutpu
t>

32

</td>

33

34

<td>

35

36

<!
---
Display the current time
---
>

37

<cfoutput>
#
timeFormat( now(),
"hh:mm:ss tt"
)
#
</cfoutput>

38

</td>

39

</tr>

40

41


<tr>

42

<td colspan =
"2"
>

43

44

<!
---
Display the output of now()
---
>

45

<cfoutput>
Date/Time:
#
now()
#
</cfoutput>

46

</td>

47

</tr>

48

</table>

49

</body>

50
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

Generated XHTML
code

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
--
XHTML comment tag
--
>

6

7
<html xmlns =
"http://www.w3.org/1999/xhtml"
>

8

<head
>

9

<title>
A Simple ColdFusion Example
</title>

10

11

<style type =
"text/css"
>

12

p

{

font
-
size
:

14pt
;

color
:
blue
}

13

td

{

background
-
color
:

black
;

color
:

yellow

}

14

</style>

15

</head>

16


17

<body>

18

19

<p><strong>
A Simple ColdFusion Example
</strong></p>

20

21

<table border =
"1"
>

22

<tr>

23

<td>

24

July 24, 2003

25

</td>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

Generated XHTML
code

(2 of 2)

26

27

<td>

28

01:56:33 PM

29

</td>

30

</tr>

31

32

<tr>

33

<td colspan =
"2"
>

34

Date/Time: {ts '2003
-
07
-
24 13:56:33'}

35

</td>

3
6

</tr>

37

</table>

38

</body>

39
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.3

Using Variables and Expressions



CFML also supports creating and manipulating
variables



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

variables.cfm

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.3 : variables.cfm

---
>

6
<!
---
Expressions using Variables and Operators.
---
>

7


8
<html xmlns =
"http://www.w3.org/1999/xhtml"
>

9

<head>

10

<title>
Expressions using Variables and Operators
</title>

11

12

<style type =
"text/css"
>

13

p
{
font
-
family
:
arial, sans
-
serif
;

14

f
ont
-
size
:
12pt
;
color
:
blue
}

15

</style>

16

</head>

17

18

<body>

19

20

<!
---
Define variables using cfset
---
>

21

<cfset
firstString
=
"One"
>

22

<cfset
secondString
=
"Four"
>

23

<cfset
first
Number
=
1
>

24

<cfset
secondNumber
=
4
>

25




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

variables.cfm

(2 of 2)

26

<!
---
Concatenate two strings
---
>

27

<cfset
combinedStrings
=
firstString
&
secondString
>

28

29

<!
---
Add two numbers
---
>

30

<cfset
addedNumbers
=
firstNumber
+
secondNumber
>

31

32

<p><strong>
Express
ions using Variables and Operators
</strong></p>

33

34
<p>

35
<cfoutput>

36

Concatenation Example:
#
combinedStrings
#

37
<br />

38

Addition Example:
#
addedNumbers
#

39
</cfoutpu
t>

40
</p>

41

42

</body>

43
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.3.1

Variables and Data Types



Variables much like variables in most other
languages


cfset


Does not produce any output


No close tag



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.3.1

Variables and Data Types

Data type

Description

Array

Indexed group of elements (one to three dimensions).

Boolean

True or false.

Date/Time

Any date or time.

List

A string with text values and delimiters.

Number

Any integer or real number.

Query

Format similar to a database t
able with named
columns and numbered rows.

String

Text enclosed in either single (
’’
) or double (
""
)
quotes.

Structure

Group of associated data using key
-
value pairs.

Fig. 27.4

ColdFusion data types.




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.3.2

Expressions and Operators


Operator

Type

+

unary positive

-

unary negative

^

exponent

*

multiplication

/

division

\

integer division

MOD

modulus

+

addition

-

subtraction

&

concatenation

EQ

equal

NEQ

not equal

LT

less than

LTE

less than or equal

GT

greater than

GTE

gr
eater than or equal

CONTAINS

contains

DOES NOT
CONTAIN

does not contain

NOT

not

AND

and

OR

or

XOR

exclusive or

EQV

equivalence

IMP

implication

Fig. 27.5

ColdFusion operator precedence.




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.4

Variable Scoping



Scope


Defines from where the variable can be accessed


Refers to the named space where the variable is stored


cfif

tag


Behaves just like
if

statements in other languages


cfelseif


cdelse


isDefined

function


Returns true or false


NOT

operator


Reverses the truth or falsity of entire expression



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.4

Variable Scoping

Scope prefix

Prefix required

References

variables

No

Local variable

form

No

Form

url

No

URL

request

Yes

HTTP request

cgi

No

CGI variable

cookie

No

Cookie

client

No

Application

session

Yes

Application

application

Yes

Application

server

Yes

Server

flash

Yes

Macromedia Flash

queryname

No

Query

Fig. 27.6

ColdFusion variable scopes.




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

name.cfm

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.7 : name.cfm

---
>

6
<!
---
Using url scope variables
---
>

7

8
<html xmlns =

"http://www.w3.org/1999/xhtml"
>

9

<head>

10

<title>
Hello
</title>

11

12

<style type =
"text/css"
>

13

p
{
font
-
family
:
arial, sans
-
serif
;

14

font
-
size
:
14pt
;
color
:
navy
}

15

</style>

16


</head>

17

18

<body>

19

20

<!
---
IF Control Structure
---
>

21

<cfif NOT
isDefined(

"url.name"

)
>

22

23

<!
---
Create default if name variable is not in the URL
---
>

24

<cfset
url.name
=
"Guest"
>



25

</cfif>





2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

name.cfm

(2 of 2)

26

27

<!
---
Display URL Variable
---
>

28

<p>
Hello
<cfoutput>
#
url.name
#
</cfoutput></p>

29

</body>

30
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.5

Form Processing



form

variable scope


Gather information from the user


isNumeric

function


Similar to
isDefined

function


Returns boolean value


Returns true if parameter is number


False otherwise



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

form.html

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
--
Fig. 27.8 : form.html

--
>

6
<!
--
A simple auction bid form
--
>

7

8
<html xmlns =
"h
ttp://www.w3.org/1999/xhtml"
>

9

<head>

10
<title>
Simple Auction
</title>

11

12

<style type =
"text/css"
>

13

p
{
font
-
family
:
arial, sans
-
serif
;

14

font
-
size
:
14pt
;
color
:
navy
}

15

</style>

16

</head>

17

18

<body>

19

20
<!
--
Form variables created using post method
--
>

21

<form action =
"form_process.cfm"
method =
"post"
>

22
<p>
Enter your bid:
</p>

23

24
<p>

25




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

form.html

(2 of 2)

26

<!
---
name attribute becomes variable name
---
>

27

$
<input name =
"bidPrice"
type =
"text"
size =
"20"
/>

28

<input type =
"submit"
value =
"Enter"
/>

29

</p>


30

</form>

31

</body>

32
</html>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

form_process.cfm

(1 of 2)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.9 : form_process.cfm

---
>

6
<!
---
A simple auction bid processing form
---
>

7

8
<html xmlns =
"http://www.w3.org/1999/xhtml"
>

9

<head>

10
<title>
Simple Auction
</title>

11

12

<style type =
"text/css"
>

13

p
{
font
-
family
:
arial, sans
-
serif
;

14

font
-
size
:
14pt
;
color
:
navy
}

15

</style>

16

</head>

17

18

<body>

19

20

<!
---
Determine if bidPrice exists
---
>

21

<cfif
isDefined(

"form.bidPrice"

)
>

22

23

<!
---
Determine if bidPrice is a number
---
>

24

<cfif
isNumeric(

form.bidPrice

)
>

25




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

form_process.cfm

(2 of 2)

26

<!
---
Determine is bidPrice is GTE 0
---
>

27

<cfif
form.bidPrice
GTE
0
>

28

29

<!
---
Display bid from form field
---
>

30
<p>

31

Your bid is:

32

<cfoutput>
$
#
form.bidPrice
#
</cfoutput>

33
</p>

34

<cfelse>


35

<p>
Your bid must be greater then or equal to $0.00!
</p>

36

</cfif>


37

38

<c
felse>


39

<p>
Your bid must be a valid numeric dollar amount!
</p>

40

</cfif>


41

42

<cfelse>


43

<p>
Error, no bid found.
</p>

44


</cfif>


45

46

</body>

47
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.6

Creating a Data Source Name


Fig. 27.10

Data source registration in the ColdFusion Administrator.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.7

Bookstore Case Study: Interface and
Database



cfquery

tag


cflocation

tag


Redirects the user to another CFML template


cfabort

tag


Instructs CFML interpreter to stop and not finish processing
page


cfloop

tag


Outputs the code between its opening and closing tags once



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

booklist.cfm

(1 of 3)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.11 : booklist.cfm
---
>

6
<!
---
Bookstore
-
List of Books
---
>

7

8
<html xm
lns =
"http://www.w3.org/1999/xhtml"
>

9

<head>

10
<title>
Book List
</title>

11

12
<style type =
"text/css"
>

13

p
{
text
-
align
:
center
}

14

h1
{
text
-
align
:
center
}

15
</style>

16

</head>

17

18

<body>

19

20
<!
---
CFML Query using SQL on 'books' Data Source Name
---
>

21

<cfquery name =
"bookList"
datasource =
"books"
>

22

SELECT ISBN, Title, EditionNumber


23

FROM Titles



24

ORDER BY Title ASC, EditionNumber DESC


25

</cfquery>





2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

booklist.cfm

(2 of 3)

26

27
<h1>
Available Books
</h1>

28

29
<hr />

30

31

<p>
Select a book from this list and click the button to

32

view the selected book's information.
</p>

33

34

<form action =
"bookinfo.cfm"
method
=
"post"
>

35

<p>

36

37

<!
---
Dynamically build select box from database
---
>

38

<select name =
"ISBN"
size =
"5"
>

39

40

<!
---
Looping results of query using cfoutput
---
>

41


<cfoutput query =
"bookList"
>


42

<option value =
"
#
bookList.ISBN
#
"
>
#
bookList.Title
#

43

(Edition
#
bookList.EditionNumber
#
)
</option>


44

</cfoutput>



45

</select>

46

</p>

47




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

booklist.cfm

(3 of 3)

48

<p><input type =
"submit"
value =
"View Information"
/></p>

49

</form>

50

</body>

51
</html>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

bookinfo.cfm

(1 of 5)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.12 : bookinfo.cfm

---
>

6
<!
---
Bookstore
-
Detailed Book Information
---
>

7

8

<html xmlns =
"http://www.w3.org/1999/xhtml"
>

9

<head>

10
<title>
Book Info
</title>

11

12
<style type =
"text/css"
>

13

table
{
border
-
collapse
:
collapse
}

14

td
{
border
:
2px solid lightgray
;

15


padding
:

5px

}

16
</style>

17

</head>

18

19

<body>

20

21

<!
---
Make sure that an ISBN was submitted to this page
---
>

22

<cfif NOT
isDefined(

"form.ISBN"

)
>

23

24
<!
---
CFML U
RL Forwarder
---
>

25

<cflocation url =
"booklist.cfm"
addtoken =
"no"
>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

bookinfo.cfm

(2 of 5)

26

<cfabort>

27

</cfif>

28

29

<!
---
CFML Query using SQL on 'books' DSN
---
>

30

<!
---
Dynamically insert form.ISBN variable
---
>

31

<cfquery name =
"bookInfo"
datasource =
"books"
>


32


SELECT ISBN, Title, EditionNumber, Copyright, Description,

33

ImageFile, PublisherName


34

FROM Titles, Publishers


35

WHERE Titles.ISBN = '
#
form.ISB
N
#
'


36

AND Titles.PublisherID = Publishers.PublisherID


37

</cfquery>


38

39

<!
---
Using cfoutput with a query to loop result set
---
>

4
0

<cfoutput query =
"bookInfo"
>

41

42

<!
---
Based on ISBN, use SQL to retrieve authors
---
>

43

<
cfq
uery name =
"authorInfo"
datasource =
"books"
>

44

SELECT FirstName, LastName

45

F
RO
M Author
ISBN, Authors

46

WHERE AuthorISBN.isbn = '
#
bookInfo.ISBN
#
'

47

AND AuthorISBN.AuthorID = Authors.AuthorID

48

</cfquery>

49

50
<h1>
#
bookInfo.Title
#
</h1>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

bookinfo.cfm

(3 of 5)

51

52
<hr />

53

54
<p>

55

56

<!
---
Display authors by using a CFML Loop
---
>

57

<cfloop query =
"authorInfo"
>


58

#
authorInfo.FirstName
#

#
authorInfo.
LastName
#

<br />

59

</cfloop>


60

</p>

61

62

<!
---
Output information from database about book
---
>

63
<table>

64

<tr>

65

<td
>
ISBN:
</td>

66

<td>
#
bookInfo.ISBN
#
</td>

67

<td rowspan =
"4"
>

68

69

<!
---
Dynamically insert the filename into the tag
---
>

70

<img src =
"images/
#
bookInfo.ImageFile
#
"

71

alt =
"Image File"
/>


72

</td>

73

</tr>

74




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

bookinfo.cfm

(4 of 5)

75

<tr>

76

<td>
Edition:
</td>

77

<td>
#
bookInfo.EditionNumber
#
</td>

78

</tr>

79

80

<tr>

81

<td>
Copyright:
</td>

82

<td>
#
bookInfo.Copyright
#
</td>

83

</tr>

84

85

<tr>

86

<td>
Publisher:
</td>

87

<td>
#
bookInfo.PublisherName
#
</td>

88

</tr>

89

</table>

90

<p>
#
bookInfo.Description
#
</p>

91

92

<!
---
Used in Section 27.8
---
>

93

<!
---
Button to add book to shopping cart
---
>

94

<form action =
"shoppingcart.cfm"
method =
"post"
>

95

<p>

96

<input type =
"hidden"
name =
"ISBN"

97

value =
"
#
bookInfo.ISBN
#
"
/>

98




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

bookinfo.cfm

(5 of 5)

99

<input type =
"hidden"
name =
"title"

100

value =
"
#
bookInfo.Title
#
"
/>

101

102

<input type =
"hidden"
name =
"edition"

103

value =
"
#
bookInfo.EditionNumber
#
"
/>

104

105

<input type =
"submit"
value =
"Add To Cart"

106

disabled =
"disabled"
/>

107

</p>

108

</form>

109

</cfoutput>

110

111

<!
---
Button to go back to the book list
---
>

112

<form action =
"booklist.cfm"
method =
"post"
>

113

<p>

114

<input type =
"submit"
value =
"Book List"
/>

115

</p>

116

</form>

117

</body>

118
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.8

Bookstore Case Study: Shopping Cart



cfapplication

tag


Access the variable scopes related to applications


client

variables


Can be stored as cookies on user’s computer or in server’s
registery


session

variables


Store contents of user’s shopping cart as user makes selections


application

variables



2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

Application.cfm

(1 of 1)

1
<!
---
Fig. 27.13 : Application.cfm

---
>

2
<!
---
Bookstore
-
Application Framework
---
>

3

4
<!
---
Initialize the application framework
---
>

5
<cfapplication name =
"bookStore"


6

client
management =
"Yes"


7

sessionmanagement =
"Yes"


8

sessiontimeout =
"
#
createTimeSpan( 0,0,20,0 )
#
"


9

applicationtimeout =
"
#
createTimeSpan( 2,0,0,0
)
#
"

10

clientstorage =
"cookie"
>


11

12
<!
---
Make sure the shopping cart exists or create one
---
>

13
<cfif NOT
isDefined(

"session.shoppingCart"

)
>

14

<cfset
session.shoppingCart
=
arrayNew(
2
)
>

15
</cfif>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

shoppingcart.cfm

(1 of 3)

1
<?xml version =
"1.0"
?>

2
<!DOCTYPE html PUBLIC
"
-
//W3C//DTD XHTML 1.1//EN"

3

"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
>

4

5
<!
---
Fig. 27.14 : shoppingcart.cfm
---
>

6
<!
---
Bookstore
-
Simple Shopping Cart
---
>

7

8

<cfif
isDefined(

"form.ISBN"

)
>

9

10

<!
---
Add a new book to the shopping cart.
---
>

11

<cfif
arrayAppend( session.shoppingCart[

1

], form.ISBN )
></cfif>


12

<cfif
arrayAppend(

session.shoppingCart[

2

], form.title )
></cfif>


13


<cfif
arrayAppend(

session.shoppingCart[

3

], form.edition )
></cfif>

14
<cfelseif
isDefined(

"form.clearCart"
)
>

15

16

<!
---
Empty the shopping cart.
---
>

17

<cfif
arrayClear( session.shoppingCart )
></cfif>

18
</cfif>

19

20
<html xmlns =
"http://www.w3.org/1999/xhtml"
>

21

<head>

22

<title>
Bookstore Shopping Cart
</title>

23

24

<style type =
"text/css"
>

25

table
{
border
-
collapse
:

collapse

}




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

shoppingcart.cfm

(2 of 3)

26

td
{
border
:

2px solid lightgray
;

27

padding
:

5px

}

28

</style>

29

</head>

30

31

<body>

32

<h1>
Shopping Cart
</h1>

33

34

<!
---
Check the size of the shopping cart
---
>

35


<cfset
arraySize
=
arrayLen( session.shoppingCart[

1

] )
>

36

37

<cfif
arraySize
GTE
1
>

38

<table>

39

40

<!
---
Display the items in the shopping cart
---
>

41

<cfloop index=
"i"
from=
"1"
to=
"
#
arr
aySize
#
"
step=
"1"
>


42

<cfoutput>


43

<tr>


44

<td>
#
session.shoppingCart[

1

][

i

]
#
</td>


45


<td>
#
session.shoppingCart[

2

][

i

]
#
</td>


46

<td>
Edition
#
session.shoppingCart[

3

]
[

i

]
#
</td>

47

</tr>


48

</cfoutput>



49

</cfloop>


50

</table>




2003 Prentice Hall, Inc.

All rights reserved.

Outline



2003 Prentice Hall, Inc.

All rights reserved.

Outline

shoppingcart.cfm

(3 of 3)

51

<cfelse>

52

<p>
Empty Shopping Cart.
</p>

53

</cfif>

54

55

<!
---
Button back to the book list
---
>

56

<form action =
"booklist.cfm"
method =
"post"
>


57

<p><input type =
"submit"
value
=
"Book List"
/></p>

58

</form>


59

60

<!
---
Button to clear the shopping cart
---
>

61

<form action =
"shoppingcart.cfm"
method =
"post"
>

62

<p>



63

<input name =
"clearCart"
type =
"submit"


64

value =
"Empty Cart"
/>


65

</p>


66

</form>



67

</body>

68
</html>




2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.9

Advanced Topics for ColdFusion
Developers



Ability to create custom tags and user
-
defined
functions


Set of built
-
in CFML tags for working with XML
and for interacting with Web services



2003 Prentice Hall, Inc. All rights reserved.



2003 Prentice Hall, Inc. All rights reserved.

27.10

Web Resources



www.macromedia.com/software/coldfusion



www.macromedia.com/support/coldfusion/documentation.html


www.macromedia.com/cfusion/exchange/index.cfm?view=sn130


www.forta.com


www.sys
-
con.com/coldfusion