>> I was wondering if anyone would post some very simple, yet complete
code
for how they implement CFCs

the call at the top of the page probably tells it all.
the CFC called has an insert, update, delete (not used), addNew, get
(existing record), setCancel (replaces delete) and init public methods.

each public method calls private methods for control, data validation,
etc.

there are a couple of page functions that basically move data between
the CFC and the FORM scopes. these are used just to keep the page
organised:
 - setObjPropertiesFromForm()
 - fillFormFromDefaults()
 - fillFormFromObject()

unless navigated away, the page display is below this logic and runs as
a default (with either the default or CFC values used).

I'm sort of emulating how ASP.NET processes a page. While I'm not
mad-keen on ASP.NET, I do like some of the way it works. The displayed
HTML is a "result" of the page processing with hardly any CF code mixed
in with the HTML (WDDX and JS helps there).

there is another CFC (reqadmin) which has methods to authorise and
calculate various totals as well as utility methods returning queries
for listboxes, etc 

I've left out the error checking because we're going to change it
(again) but I typically try/catch any query in the db and (depending)
return true/false on it's success or cfrethrow the error for the calling
code to catch. I'll let others chip in here - I can't do it justice ATM.

hopefully this should be food for thought 


cheers
barry.b

anyway, the call the main CFC.

<cfset objRequisition = createobject("component",
"#APPLICATION.componentPath#.requisition").init(dsnInfo, cmpy)>
<cfif isDefined("form.fieldnames")>
        <cfset prevAction = "">
        <cfset theReqNum = 0>
        <cfif isNew><!--- a new form to process --->
                <cfset setObjPropertiesFromForm(objRequisition)>
                <cfset theReqNum = objRequisition.AddNew()>
                <cfset prevAction = "saved">
        <cfelseif isEdit><!--- save the edited form --->
                <cfset setObjPropertiesFromForm(objRequisition)>

                <cfset theReqNum = objRequisition.Update()>
                <cfset prevAction = "updated">          
        <cfelse><!--- none of the above, go home --->
                <cfabort>
        </cfif>
        <cflocation
url="#thispage#?action=addnew&prevAction=#prevAction#&theReqNum=#theReqN
um#">
<cfelseif isCancel>     
        <cfset objRequisition.SetCancel(URL.req)>
        <cflocation url="reqhome.cfm">
<cfelse><!--- run set up to display form --->
        <cfif isNew><!--- brand new form --->
                <cfset fillFormFromDefaults()>
        <cfelseif isEdit><!--- edit form --->
                <cfset objRequisition.get(URL.req)>
                <cfset fillFormFromObject(objRequisition)>
        <cfelse><!--- none of the above, go home --->
                <cfabort>       
        </cfif>
</cfif>

----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the words 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

An archive of the CFCDev list is available at www.mail-archive.com/[EMAIL PROTECTED]

Reply via email to