Creating the get method
The
method has a specific signature. It returns one record from the database, as a CFC
get
instance. It appears as follows:
<cffunction name="get" output="no" returnType="samples.contact.Contact"
access="remote">
<cfargument name="uid" type="struct" required="yes">
<cftry>
<!--- This is the user to look up. --->
<cfset key = uid.contactId>
<cfset dao = CreateObject("component", "samples.contact.ContactDAO")>
<cfset ret="">
<cfset ret=dao.read(id=key)>
<cfif ArrayLen(ret) EQ 1>
<cfreturn ret[1]>
<cfelseif ArrayLen(ret) GT 1>
<cfset co.fail("get returned more than one record when contactId
had a value of #key#.")>
<cfelse>
<cfset co.fail("get did not return anything when contactId had a
value of #key#.")>
</cfif>
<!--- If the SQL failed, mark this change with the error. --->
<cfcatch type="database">
<cfset msg = "Error during get: " & cfcatch.queryError & ". SQL
was :" & cfcatch.sql>
<cfset co.fail(msg)>
</cfcatch>
<!--- If anything else happened, mark this change with the error. --->
<cfcatch type="any">
<cfset co.fail(cfcatch.message & " " & cfcatch.detail)>
</cfcatch>
</cftry>
</cffunction>
Example application
53
Need help?
Do you have a question about the COLDFUSION MX 7.0.2-USING COLDFUSION MX WITH FLEX 2 and is the answer not in the manual?
Questions and answers