Object Oriented Coldfusion : 7.2 : Basic DAO Example
Posted on October 23, 2007
Ok, so we’ve got the concept of a DAO and how it interacts with a bean. Here’s an example of a form and an action page using Object Oriented Coldfusion.
A Form and an Action page
Let’s say you’ve got a page with a list of Contacts, each item has a link to contact_form.cfm with the CONTACT_ID in the query string.
contact_list.cfm
<cfset contactList = application.ContactGateway.getContacts() />
<ul>
<cfoutput query="contactList">
<li>
<a href="contact_form.cfm?CONTACT_ID=#contactList.CONTACT_ID#">
#contactList.LAST_NAME#, #contactList.FIRST_NAME#
</a>
</li>
</cfoutput>
</ul>
### output
- Filch, Argus
- Granger, Hermione
- McGonagall, Minerva</li>
- Potter, Harry
- Harry, Ron
</ul> ### Updating a record This form is going to update an existing record. ### contact_form.cfm?CONTACT_ID=3 ```cfscript<cfset categories = application.categoryGateway.getCategories() /> <cfset contact = createObject("component", "Contact").init( CONTACT_ID = url.CONTACT_ID ) /> <cfset application.contactDAO.read( contact ) />
About the Author
Adrian J. Moreno
Adrian is a CTO and solution architect specializing in software modernization. More information