Using Structures With CFCs By Selene Bainum. June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion.

Slides:



Advertisements
Similar presentations
Access 2007 ® Use Databases How can Microsoft Access 2007 help you structure your database?
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
ASP.NET Programming with C# and SQL Server First Edition
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1.
DATA, DATABASES, AND QUERIES Managing Data in Relational Databases CS1100Microsoft Access - Introduction1 Created By Martin Schedlbauer
Building + Consuming WebServices CF Style Kevin Penny MMCP (4.5/5/MX6)
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
1 Insert, Update and Delete Queries. 2 Return to you Address Book database. Insert a record.
Working with cursors in Python GISDE Python Workshop Qiao Li.
JavaScript & jQuery the missing manual Chapter 11
Flash Remoting Chafic Kazoun Senior Flash Developer - B-Line Express Work: Play:
XML, CFMX CFML & SQL XML Kevin Penny, MMCP
Server-side Scripting Powering the webs favourite services.
4-1 INTERNET DATABASE CONNECTOR Colorado Technical University IT420 Tim Peterson.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.
Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Selene Bainum RiteTech LLC.  Doing ColdFusion & SQL development for more than 1/3 of my lifetime  Chief RiteTech  RiteTech is my company.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 11 - JavaScript: Arrays Outline 11.1 Introduction 11.2 Arrays 11.3 Declaring and Allocating Arrays.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Week 9 PHP Cookies and Session Introduction to JavaScript.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Transfer 101 Dan Vega. 2www.cfunited.com About Me Programmer ColdFusion / Flex / AS3 / HTML / JS / CSS / Groovy & Grails Cleveland ColdFusion.
JSTL, XML and XSLT An introduction to JSP Standard Tag Library and XML/XSLT transformation for Web layout.
Utilizing XML in ColdFusion MX by Attila Domokos.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Website Development with PHP and MySQL Saving Data.
Chapter 17 Creating a Database.
ITCS373: Internet Technology Lecture 5: More HTML.
Improving Database Performance Derrick Rapley
XML and Database.
PROGRAMMING LANGUAGES: PROLOG, CLOJURE, F# Jared Wheeler.
Table of Contents TopicSlide Administrator Login 2 Administrator Navigations 3 Managing AlternativeDr.com Blogs 4 Managing Dr. Lloyd May Blogs 5 Managing.
CFUNITED – The premier ColdFusion conference ColdFusion Components Ajay Sathuluri Based on presentation.
1 of 16 Microsoft ® Business Solutions–Navision ® Development I – C/SIDE Introduction.
Unit 12 JavaScript Arrays Instructor: Brent Presley.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
Tutorial 11 1 JavaScript Operators and Expressions.
 Java Server Pages (JSP) By Offir Golan. What is JSP?  A technology that allows for the creation of dynamically generated web pages based on HTML, XML,
Data Structures Arrays and Lists Part 2 More List Operations.
Building a ColdFusion CMS with Dreamweaver and the MX Kollection in less than 50 minutes Bogdan Ripa InterAKT Online.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
A Presentation Presentation On JSP On JSP & Online Shopping Cart Online Shopping Cart.
Web Database Programming Using PHP
CS 371 Web Application Programming
Practical Office 2007 Chapter 10
Web Database Programming Using PHP
Variables and Conditions Nicholas Tunney Senior Software Architect
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web DB Programming: PHP
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Creating and Consuming Web Services with CFML
Presentation transcript:

Using Structures With CFCs By Selene Bainum

June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion Components (CFCs) Learn how to effectively use the two together

June 27 th - 30 th 2007www.cfunited.com About Me Extensive SQL & database development since 1995 ColdFusion Developer since 1996 Member, Team since 1997 Author  Mastering ColdFusion MX (Co-author)  ColdFusion MX Developer’s Handbook (Co-author)  ColdFusion Developer’s Journal Run WebTricks.com Business Systems Architect, INPUT

June 27 th - 30 th 2007www.cfunited.com OverviewOverview Structure & CFC Refresher Calling Functions Sample Application – Address Book Using Structures/CFCs with Sample Application Code Examples Conclusion / Q&A

June 27 th - 30 th 2007www.cfunited.com Structure Refresher Complex data types Introduced in ColdFusion 4.5 Logical grouping of data Associative Arrays Made up of key/value pairs Keys stored/returned in no particular order Passed by reference, not value

June 27 th - 30 th 2007www.cfunited.com Built-In ColdFusion Structures Server Application Session Request Form URL Variables Arguments  Within functions

June 27 th - 30 th 2007www.cfunited.com CFC Refresher Components contains functions Zero or many arguments may be passed to functions Zero or one value can be returned from a function Argument and return variables are typed

June 27 th - 30 th 2007www.cfunited.com Valid Argument/Return Types Any Array Binary Boolean Date Numeric Query String Struct UUID Variablename Void* XML * only valid for return types

June 27 th - 30 th 2007www.cfunited.com Calling Functions Tags  cfinvoke tag calls component/function  Arguments passed by: a) cfinvokeargument tag nested in cfinvoke tag b) Named attributes of the cfinvoke tag c) args attribute of cfinvoke tag Script  CreateObject method instantiates component  Function called  Arguments passed as parameters of function call  Use name/value pairs

June 27 th - 30 th 2007www.cfunited.com Sample Function <cfargument name=“ContactID” type=“numeric” required=“yes” /> …

June 27 th - 30 th 2007www.cfunited.com Calling Functions - Tags <cfinvoke component=“contact” method=“getContactDetail” returnvariable=“ContactStruct”> <cfinvokeargument name=“ContactID” value=“#URL.ContactID#” />

June 27 th - 30 th 2007www.cfunited.com Calling Functions - Tags <cfinvoke component=“contact” method=“getContactDetail” returnvariable=“ContactStruct” ContactID=“#URL.ContactID#” />

June 27 th - 30 th 2007www.cfunited.com Calling Functions - Tags <cfinvoke component=“contact” method=“getContactDetail” returnvariable=“ContactStruct” args=“#ArgStruct#” />

June 27 th - 30 th 2007www.cfunited.com Calling Functions - Scripts /* Call the component/function and get the contact’s details by passing the ContactID as a parameter of the function. */ ContactStruct = CreateObject(“component”, “contact”).getContactDetail( ContactID = URL.ContactID );

June 27 th - 30 th 2007www.cfunited.com Why I Prefer Using CFScript CFScript more efficient than using tags? – debatable point I think it looks cleaner and is easier to follow Too lazy to type repeatedly More consistent, only one way to pass arguments to function

June 27 th - 30 th 2007www.cfunited.com Benefits of Using Structures Less arguments to declare in function Less arguments to declare in function calls New elements can be added to structure without changing function declaration or calls Allows use of built-in structure and array tags and functions

June 27 th - 30 th 2007www.cfunited.com Drawbacks of Using Structures Argument typing is built-in validation/security Built-in typing only works on the root of the structure/array, not on individual elements Typing/validation must be done manually  cfqueryparam important here! No easy way to see all available arguments without manually commenting

June 27 th - 30 th 2007www.cfunited.com Arguments as Structure Within functions, Arguments is a structure Each cfargument tag defines a key of the structure When args attribute of cfinvoke is used, keys of the args structure are matched with cfargument declarations

June 27 th - 30 th 2007www.cfunited.com Address Book Application Address book similar to Microsoft Web Outlook Contacts Each contact has:  Contact information  Zero or more phone numbers  Zero or more addresses Contacts can be listed, modified and searched

June 27 th - 30 th 2007www.cfunited.com Contact Listing Screenshot

June 27 th - 30 th 2007www.cfunited.com Contact Edit Screenshot

June 27 th - 30 th 2007www.cfunited.com Address Book Database * Disclaimer: “Friends don’t let friends use Access”

June 27 th - 30 th 2007www.cfunited.com Key Application Files contact.cfc  Component that works with contact tables phone.cfc  Component that works with phone number tables address.cfc  Component that works with address tables act_contact_add_edit_init.cfm  File that initializes the contact details structure for add/edits

June 27 th - 30 th 2007www.cfunited.com contact.cfccontact.cfc getContactList(): query  Returns a query of contacts  Arguments: a)SortBy: string, optional b)SearchStruct: struct, optional getContactDetail(): struct  Returns a structure of the details of a contact  Arguments: a)ContactID: numeric, required

June 27 th - 30 th 2007www.cfunited.com contact.cfccontact.cfc addContact(): numeric  Creates a new contact and returns the ContactID Value  Arguments: a)ContactStruct: struct, required editContact(): void  Updates an existing contact  Arguments: a)ContactStruct: struct, required deleteContact(): void  Deletes an existing contact  Arguments: a)ContactID: numeric, required

June 27 th - 30 th 2007www.cfunited.com phone.cfcphone.cfc getPhoneNumberTypes(): query  Returns a query of the type of phone numbers getContactPhoneNumbers(): query  Returns a query of the phone numbers for a contact  Arguments: a)ContactID: numeric, required addUpdateContactPhoneNumbers(): void  Deletes any existing phone numbers for a contact and inserts new ones  Arguments: a)ContactID: numeric, required b)PhoneNumberStruct: struct, required

June 27 th - 30 th 2007www.cfunited.com address.cfcaddress.cfc getAddressTypes(): query  Returns a query of the type of addresses getContactAddresses(): query  Returns a query of the addresses for a contact  Arguments: a)ContactID: numeric, required addUpdateContactAddresses(): void  Deletes any existing addresses for a contact and inserts new ones  Arguments: a)ContactID: numeric, required b)AddressStruct: struct, required

June 27 th - 30 th 2007www.cfunited.com Contact Detail Returns Structure One contact has zero or many phone numbers One contact has zero or many addresses Structure allows all elements to be returned as one variable

June 27 th - 30 th 2007www.cfunited.com Contact Detail SELECT C.ContactID, … FROM Contact C WHERE C.ContactID = // Create return struct ReturnStruct = StructNew(); // Add detail query to structure by looping over items for (i = 1; i LTE ListLen(qryGetContactDetail.ColumnList); i = i + 1) { ReturnStruct[ListGetAt(qryGetContactDetail.ColumnList, i)] = qryGetContactDetail[ListGetAt(qryGetContactDetail.ColumnList, i)][1]; }

June 27 th - 30 th 2007www.cfunited.com Contact Detail Continued // Get phone numbers and add to the structure qryGetContactPhoneNumbers = Application.objPh.getContactPhoneNumbers( ContactID = Arguments.ContactID ); ReturnStruct.PhoneNumbers = StructNew(); for (i = 1; i LTE qryGetContactPhoneNumbers.RecordCount; i = i + 1) { thisID = qryGetContactPhoneNumbers.PhoneNumberTypeID[i]; ReturnStruct.PhoneNumbers[thisID] = StructNew(); Returnstruct.PhoneNumbers[thisID].PhoneNumberTypeTx = qryGetContactPhoneNumbers.PhoneNumberTypeTx[i]; Returnstruct.PhoneNumbers[thisID].ContactPhoneNumberTypeValueTx = qryGetContactPhoneNumbers.ContactPhoneNumberTypeValueTx[i]; }

June 27 th - 30 th 2007www.cfunited.com Contact Detail Continued // Get address and add to the structure qryGetContactAddresses = Application.objAd.getContactAddresses( ContactID = Arguments.ContactID ); ReturnStruct.Addresses = StructNew(); for (i = 1; i LTE qryGetContactAddresses.RecordCount; i = i + 1) { thisID = qryGetContactAddresses.AddressTypeID[i]; ReturnStruct.Addresses[thisID] = StructNew(); Returnstruct.Addresses[thisID].ContactAddressTypeStreetTx = qryGetContactAddresses.ContactAddressTypeStreetTx[i]; }

June 27 th - 30 th 2007www.cfunited.com Contact Detail Structure

June 27 th - 30 th 2007www.cfunited.com Add/Edit Contact Detail structure retrieved for edit Full structure generated with cfparam tags Form pre-populated with structure values Form values moved back into structure Structure passed to add/edit functions

June 27 th - 30 th 2007www.cfunited.com ExamplesExamples Building the contact’s details Initializing contact structure Add/edit form Add/edit process Comparison of process without structures

June 27 th - 30 th 2007www.cfunited.com Contact Listing/Search One function for retrieving list of contacts: getContactList() Two optional arguments  SortBy: string, default=“ContactLastNameTx”  SearchStruct: struct If SearchStruct not defined, all contacts returned If SearchStruct is defined, individual structure keys checked for definition and length – used for filters

June 27 th - 30 th 2007www.cfunited.com Contact Search Available search criteria:  Name  Company  Phone Number  Address On submit, FORM structure passed to getContactList function

June 27 th - 30 th 2007www.cfunited.com ExamplesExamples Search form Calling search function Building dynamic query Comparison of process without structures

June 27 th - 30 th 2007www.cfunited.com Thank You! Selene Bainum Don’t forget to fill out the evaluation!

June 27 th - 30 th 2007www.cfunited.com Questions & Answers