Enhancing the Trip Maintenance application
113
Reviewing the code
The following table describes the code used to process the navigation button requests:
Exercise: implement trip record browsing (navigation)
Follow these steps to implement the trip record browsing functionality (navigation buttons) on
the Trip Detail page. In this exercise, you will use the supplied navigation action page to
implement and test the navigation buttons on the Trip Detail page.
To implement the trip record browsing functionality:
1
Copy the navigationaction.cfm file from the solutions subdirectory in the getting_started
directory to the my_app directory.
2
View the tripdetail.cfm page from the my_app directory in a browser and test the navigation
buttons as follows:
a
Click Next Row.
The Trip Detail page shows information about the second trip.
Code Explanation
<cfquery
name="TripQuery"
dataSource="compasstravel"
maxRows=1>
The
cfquery
tag identifies that a query
named "TripQuery" will be executed
against the "CompassTravel" data
source. The number of rows returned
cannot exceed 1 (
maxRows
=1).
SELECT tripID FROM trips
The SQL SELECT statement will
always start with "SELECT tripID
FROM trips".
<cfif IsDefined("Form.btnPrev.X")>
WHERE tripID < #Form.RecordID#
ORDER BY tripID DESC
<cfelseif IsDefined("Form.btnNext.X")>
WHERE tripID > #Form.RecordID#
ORDER BY tripID
<cfelseif IsDefined("Form.btnFirst.X")>
ORDER BY tripID
<cfelseif IsDefined("Form.btnLast.X")>
WHERE tripID > #Form.RecordID#
ORDER BY tripID DESC
</cfif>
</cfquery>
The
cfif
tag checks if the user pressed
a navigation button on the browse page.
The X property is checked since the
buttons on the detail page use image
type HTML input tags. The X property is
a mouse offset that gets sent when you
click a graphic button.
The WHERE and ORDER BY clauses
will vary depending on the navigation
button clicked by the user.
<cfif TripQuery.RecordCount is 1>
<cflocation
url="tripdetail.cfm?RecordID=#TripQuery.tripID#">
<cfelse>
<cflocation
url="tripdetail.cfm?RecordID=#Form.RecordID#">
</cfif>
The
cfif
tag checks if the query
returned a row to display. If it did, use
that
tripID
to form a URL to navigate to
using the
cflocation
tag. If the query
returned no rows, navigate back to the
detail page with current record id
passed in the hidden form variable
RecordID
.
Содержание COLDFUSION MX 61-GETTING STARTED BUILDING COLDFUSION...
Страница 1: ...Getting Started Building ColdFusion MX Applications...
Страница 6: ...6 Contents...
Страница 10: ......
Страница 30: ...30 Chapter 2 CFML Basics...
Страница 36: ...36 Chapter 3 Database Fundamentals...
Страница 48: ......
Страница 76: ...76 Chapter 6 Lesson 2 Writing Your First ColdFusion Application...
Страница 134: ...134 Index...