Flash Builder 4通过LCDS31 Data Management访问Coldfusion的CFCs

Coldfusion901上已经集成LCDS31,现在通过LCDSData Management访问CF的自定义组件。

1.      俺使用Mysql5,并建立一个用户les001,用于CF的数据服务访问Mysql的,使用的数据库名称为xtjc,这个可以参考前文<<ColdfusionLCDS部署在JBOSS >>,使用表workcalendar,数据如图;

 

2.      修改CF_WWWROOT/WEB-INF/flex目录下文件services-config.xml,取消channel-definitio id="cf-rtmp"的节点注释,写法大致如下;

 

<channel-definition id="cf-rtmp" class="mx.messaging.channels.RTMPChannel">

            <endpoint uri="rtmp://{server.name}:2048" class="coldfusion.flash.messaging.CFRTMPEndPoint"/>

            <properties>

                <idle-timeout-minutes>20</idle-timeout-minutes>

                       <serialization>

                              <enable-small-messages>false</enable-small-messages>

                       </serialization>

                       <coldfusion>

 

                              <access>

                                     <use-mappings>true</use-mappings>

                                     <method-access-level>remote</method-access-level>

                              </access>

 

                              <use-accessors>true</use-accessors>

                             

                              <use-structs>false</use-structs>

                             

                              <property-case>

                        <force-cfc-lowercase>false</force-cfc-lowercase>

                        <force-query-lowercase>false</force-query-lowercase>

                        <force-struct-lowercase>false</force-struct-lowercase>

                    </property-case>

                       </coldfusion>

            </properties>

        </channel-definition>

 

 

3.      还要配置channel-definitio id="cf-polling-amf"的节点,写法大致如下;

 

<channel-definition id="cf-polling-amf" class="mx.messaging.channels.AMFChannel">

            <endpoint uri="http://{server.name}:{server.port}{context.root}/flex2gateway/cfamfpolling" class="coldfusion.flash.messaging.CFAMFEndPoint"/>

            <properties>

                <polling-enabled>true</polling-enabled>

                <polling-interval-seconds>8</polling-interval-seconds>

                       <serialization>

                              <enable-small-messages>false</enable-small-messages>

                       </serialization>

     </properties>

 </channel-definition>

 

4.      修改CF_WWWROOT/WEB-INF/flex目录下文件data-management-config.xml,增加俺的destination

 

  <destination id="workcalendar">

                <adapter ref="coldfusion-dao"/>

                <channels>

                    <channel ref="cf-polling-amf"/>

                </channels>

                <properties>

                    <component>com.les.visual.workcalendarAssembler</component>

                    <scope>request</scope>

                    <metadata>

                        <identity property="id"/>

                                          <query-row-type>com.les.visual.workcalendar</query-row-type>

                    </metadata>

                </properties>

    </destination>

标记<component>com.les.visual.workcalendarAssembler</component>指出俺的编译类名称,标记<query-row-type>com.les.visual.workcalendar</query-row-type>指出俺的行记录集的映射类

 

 

5.      FB4暂时没有创建CF901编译类的Wizard,俺借助FB3创建编译类,分别是workcalendar.cfcworkcalendarAssembler.cfcworkcalendarDAO.cfcworkcalendar.as

 

6.      先介绍workcalendar.as文件,这个是flash的数据映射类

    package com.les.visual

{

[Managed]

[RemoteClass(alias="com.les.visual.workcalendar")]

 

public class workcalendar

{

 

        public var id:Number = 0;

        public var Name:String = "";

        public var Workdate:Date = null;

        public var Worktime:Date = null;

        public var Direction:Number = 0;

        public var Halfrest:Number = 0;

 

 

        public function workcalendar()

        {

        }

 

}

}

关键要加上类说明     [RemoteClass(alias="com.les.visual.workcalendar")]

 

 

7.      workcalendar.cfc这个Bean File也是说明表workcalendar字段(属性)的。

<cfcomponent output="false" alias="com.les.visual.workcalendar">

    <!---

        These are properties that are exposed by this CFC object.

        These property definitions are used when calling this CFC as a web services,

        passed back to a flash movie, or when generating documentation

 

        NOTE: these cfproperty tags do not set any default property values.

    --->

    <cfproperty name="id" type="numeric" default="0">

    <cfproperty name="Name" type="string" default="">

    <cfproperty name="Workdate" type="date" default="">

    <cfproperty name="Worktime" type="date" default="">

    <cfproperty name="Direction" type="numeric" default="0">

    <cfproperty name="Halfrest" type="numeric" default="0">

 

    <cfscript>

       //Initialize the CFC with the default properties values.

       variables.id = 0;

       variables.Name = "";

       variables.Workdate = "";

       variables.Worktime = "";

       variables.Direction = 0;

       variables.Halfrest = 0;

    </cfscript>

 

    <cffunction name="init" output="false" returntype="workcalendar">

       <cfreturn this>

    </cffunction>

    <cffunction name="getId" output="false" access="public" returntype="any">

       <cfreturn variables.Id>

    </cffunction>

 

    <cffunction name="setId" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Id = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getName" output="false" access="public" returntype="any">

       <cfreturn variables.Name>

    </cffunction>

 

    <cffunction name="setName" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfset variables.Name = arguments.val>

    </cffunction>

 

    <cffunction name="getWorkdate" output="false" access="public" returntype="any">

       <cfreturn variables.Workdate>

    </cffunction>

 

    <cffunction name="setWorkdate" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsDate(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Workdate = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid date"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getWorktime" output="false" access="public" returntype="any">

       <cfreturn variables.Worktime>

    </cffunction>

 

    <cffunction name="setWorktime" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsDate(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Worktime = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid date"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getDirection" output="false" access="public" returntype="any">

       <cfreturn variables.Direction>

    </cffunction>

 

    <cffunction name="setDirection" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Direction = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

 

    <cffunction name="getHalfrest" output="false" access="public" returntype="any">

       <cfreturn variables.Halfrest>

    </cffunction>

 

    <cffunction name="setHalfrest" output="false" access="public" returntype="void">

       <cfargument name="val" required="true">

       <cfif (IsNumeric(arguments.val)) OR (arguments.val EQ "")>

           <cfset variables.Halfrest = arguments.val>

       <cfelse>

           <cfthrow message="'#arguments.val#' is not a valid numeric"/>

       </cfif>

    </cffunction>

</cfcomponent>

 

8.      workcalendarDAO.cfc这个DAO,是负责与数据库打交道的,提取数据,创建数据,修改数据和删除数据等工作。

<cfcomponent output="false">

 

    <cffunction name="read" output="false" access="public" returntype="com.les.visual.workcalendar[]">

       <cfargument name="id" required="false">

       <cfargument name="param" required="false">

       <cfset var qRead="">

       <cfset var obj="">

       <cfset var ret = ArrayNew(1)>

 

       <cfquery name="qRead" datasource="MSSQL2008R2">

           select id, Name, Workdate, Worktime, Direction, Halfrest

                 

           from workcalendar

           <cfif structKeyExists(arguments, "id")>

              where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />

           <cfelseif structKeyExists(arguments, "param")>

              <!---

                  adjust this where clause to fit your needs (based on what you want to filter by

                  (ie if you wanted to filter by LastName, pass in what you want to filter by in

                  the "param" attribute of the function and change "where fieldname" to

                  "where LastName" below)

 

                  by default, it will probably throw an error as invalid SQL

              --->

              <!--- where fieldname LIKE '%' & <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.param#"/> & '%' --->

           </cfif>

       </cfquery>

 

       <cfloop query="qRead">

           <cfscript>

              obj = createObject("component", "com.les.visual.workcalendar").init();

              obj.setid(qRead.id);

              obj.setName(qRead.Name);

              obj.setWorkdate(qRead.Workdate);

              obj.setWorktime(qRead.Worktime);

              obj.setDirection(qRead.Direction);

              obj.setHalfrest(qRead.Halfrest);

              ArrayAppend(ret, obj);

           </cfscript>

       </cfloop>

       <cfreturn ret>

    </cffunction>

 

 

 

    <cffunction name="create" output="false" access="public">

       <cfargument name="bean" required="true" type="com.les.visual.workcalendar">

       <cfset var qCreate="">

 

       <cfset var qGetId="">

 

       <cfset var local1=arguments.bean.getName()>

       <cfset var local2=arguments.bean.getWorkdate()>

       <cfset var local3=arguments.bean.getWorktime()>

       <cfset var local4=arguments.bean.getDirection()>

       <cfset var local5=arguments.bean.getHalfrest()>

 

       <cftransaction isolation="read_committed">

           <cfquery name="qCreate" datasource="MSSQL2008R2">

              insert into workcalendar(Name, Workdate, Worktime, Direction, Halfrest)

              values (

                  <cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />,

                  <cfqueryparam value="#local2#" cfsqltype="CF_SQL_DATE" null="#iif((local2 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIME" null="#iif((local3 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />,

                  <cfqueryparam value="#local5#" cfsqltype="CF_SQL_INTEGER" null="#iif((local5 eq ""), de("yes"), de("no"))#" />

              )

           </cfquery>

 

           <!--- If your server has a better way to get the ID that is more reliable, use that instead --->

           <cfquery name="qGetID" datasource="MSSQL2008R2">

              select id

              from workcalendar

              where Name = <cfqueryparam value="#local1#" cfsqltype="CF_SQL_VARCHAR" />

                and Workdate = <cfqueryparam value="#local2#" cfsqltype="CF_SQL_DATE" null="#iif((local2 eq ""), de("yes"), de("no"))#" />

                and Worktime = <cfqueryparam value="#local3#" cfsqltype="CF_SQL_TIME" null="#iif((local3 eq ""), de("yes"), de("no"))#" />

                and Direction = <cfqueryparam value="#local4#" cfsqltype="CF_SQL_INTEGER" null="#iif((local4 eq ""), de("yes"), de("no"))#" />

                and Halfrest = <cfqueryparam value="#local5#" cfsqltype="CF_SQL_INTEGER" null="#iif((local5 eq ""), de("yes"), de("no"))#" />

              order by id desc

           </cfquery>

       </cftransaction>

 

       <cfscript>

           arguments.bean.setid(qGetID.id);

       </cfscript>

       <cfreturn arguments.bean />

    </cffunction>

 

 

 

    <cffunction name="update" output="false" access="public">

       <cfargument name="oldBean" required="true" type="com.les.visual.workcalendar">

       <cfargument name="newBean" required="true" type="com.les.visual.workcalendar">

       <cfset var qUpdate="">

 

       <cfquery name="qUpdate" datasource="MSSQL2008R2" result="status">

           update workcalendar

           set Name = <cfqueryparam value="#arguments.newBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />,

              Workdate = <cfqueryparam value="#arguments.newBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" null="#iif((arguments.newBean.getWorkdate() eq ""), de("yes"), de("no"))#" />,

              Worktime = <cfqueryparam value="#arguments.newBean.getWorktime()#" cfsqltype="CF_SQL_TIME" null="#iif((arguments.newBean.getWorktime() eq ""), de("yes"), de("no"))#" />,

              Direction = <cfqueryparam value="#arguments.newBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.newBean.getDirection() eq ""), de("yes"), de("no"))#" />,

              Halfrest = <cfqueryparam value="#arguments.newBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" null="#iif((arguments.newBean.getHalfrest() eq ""), de("yes"), de("no"))#" />

           where id = <cfqueryparam value="#arguments.oldBean.getid()#" cfsqltype="CF_SQL_INTEGER" />

             and Name = <cfqueryparam value="#arguments.oldBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />

             and Workdate = <cfqueryparam value="#arguments.oldBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" />

             and Worktime = <cfqueryparam value="#arguments.oldBean.getWorktime()#" cfsqltype="CF_SQL_TIME" />

             and Direction = <cfqueryparam value="#arguments.oldBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" />

             and Halfrest = <cfqueryparam value="#arguments.oldBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" />

       </cfquery>

       <!--- if we didn't affect a single record, the update failed --->

       <cfquery name="qUpdateResult" datasource="MSSQL2008R2"  result="status">

           select id

           from workcalendar

           where id = <cfqueryparam value="#arguments.newBean.getid()#" cfsqltype="CF_SQL_INTEGER" />

             and Name = <cfqueryparam value="#arguments.newBean.getName()#" cfsqltype="CF_SQL_VARCHAR" />

             and Workdate = <cfqueryparam value="#arguments.newBean.getWorkdate()#" cfsqltype="CF_SQL_DATE" />

             and Worktime = <cfqueryparam value="#arguments.newBean.getWorktime()#" cfsqltype="CF_SQL_TIME" />

             and Direction = <cfqueryparam value="#arguments.newBean.getDirection()#" cfsqltype="CF_SQL_INTEGER" />

             and Halfrest = <cfqueryparam value="#arguments.newBean.getHalfrest()#" cfsqltype="CF_SQL_INTEGER" />

       </cfquery>

       <cfif status.recordcount EQ 0>

           <cfthrow type="conflict" message="Unable to update record">

       </cfif>

       <cfreturn arguments.newBean />

    </cffunction>

 

 

 

    <cffunction name="delete" output="false" access="public" returntype="void">

       <cfargument name="bean" required="true" type="com.les.visual.workcalendar">

       <cfset var qDelete="">

 

       <cfquery name="qDelete" datasource="MSSQL2008R2" result="status">

           delete

           from workcalendar

           where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.getid()#" />

       </cfquery>

 

       <!--- Did we delete the record? --->

       <cfquery name="qDeleteResult" datasource="MSSQL2008R2"  result="status">

           select id

           from workcalendar

           where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.bean.getid()#" />

       </cfquery>

       <cfif status.recordcount NEQ 0>

           <cfthrow type="conflict" message="Unable to delete record">

       </cfif>

 

    </cffunction>

 

    <cffunction name="count" output="false" access="public" returntype="Numeric">

       <cfargument name="id" required="false">

       <cfargument name="param" required="false">

       <cfset var qRead="">

 

       <cfquery name="qRead" datasource="MSSQL2008R2">

           select COUNT(*) as totalRecords

           from workcalendar

           <cfif structKeyExists(arguments, "id")>

              where id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#arguments.id#" />

           <cfelseif structKeyExists(arguments, "param")>

              <!---

                  adjust this where clause to fit your needs (based on what you want to filter by

                  (ie if you wanted to filter by LastName, pass in what you want to filter by in

                  the "param" attribute of the function and change "where fieldname" to

                  "where LastName" below)

 

                  by default, it will probably throw an error as invalid SQL

              --->

              <!--- where fieldname LIKE '%' & <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#arguments.param#"/> & '%' --->

           </cfif>

       </cfquery>

 

       <cfreturn qRead.totalRecords>

    </cffunction>

</cfcomponent>

 

9.      workcalendarAssembler.cfc认可fill(),Sync(),Get(),Count()方法,是FB4(编译后Flash)调度函数。fill从数据库提取数据集填充Flash组件,get从数据库提取指定数据,

syncFlash组件和数据库之间同步数据,count计算结果集数据量。

<cfcomponent output="false">

 

  <!--- Code executed when component is created --->

  <cfscript>

         // Create a Data Access Object for this assembler instance

         variables.dao = CreateObject("component", "com.les.visual.workcalendarDAO");

  </cfscript>

 

  <cffunction name="fill" output="no" returntype="com.les.visual.workcalendar[]" access="remote">

         <cfargument name="param" type="string" required="no">

 

         <cftry>

                <cfif structKeyExists(arguments, "param")>

                       <cfreturn variables.dao.read(param=arguments.param)>

                <cfelse>

                       <cfreturn variables.dao.read()>

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during fill: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during fill: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during fill: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

  <cffunction name="get" output="no" returnType="com.les.visual.workcalendar" access="remote">

         <cfargument name="uid" type="struct" required="yes">

 

         <cftry>

                <!--- This is the record to look up --->

                <cfset key = uid.id>

 

                <cfset ret="">

                <cfset ret=variables.dao.read(id=key)>

 

                <cfif ArrayLen(ret) EQ 1>

                       <cfreturn ret[1]>

                <cfelseif ArrayLen(ret) GT 1>

                       <cfset msg="get returned more than one record when id had a value of #key#.">

                       <cfthrow message="#msg#">

                <cfelse>

                       <cfset msg="get did not return anything when id had a value of #key#.">

                       <cfthrow message="#msg#">

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during get: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during get: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during get: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

  <cffunction name="sync" output="no" returnType="array" access="remote">

         <cfargument name="changes" type="array" required="yes">

 

         <!-- array for the returned changes -->

         <cfset var newchanges=ArrayNew(1)>

 

         <!-- Loop over the changes and apply them --->

         <cfloop from="1" to="#ArrayLen(changes)#" index="i" >

                <cfset co = changes[i]>

                <cfif co.isCreate()>

                       <cfset x = doCreate(co)>

                <cfelseif co.isUpdate()>

                       <cfset x = doUpdate(co)>

                <cfelseif co.isDelete()>

                       <cfset x = doDelete(co)>

                </cfif>

                <cfset ArrayAppend(newchanges, x)>

         </cfloop>

 

         <!-- Return the change objects, as this is how success or failure is indicated --->

         <cfreturn newchanges>

  </cffunction>

 

  <cffunction name="count" output="no" returntype="Numeric" access="remote">

         <cfargument name="param" type="string" required="no">

 

         <cftry>

                <cfif structKeyExists(arguments, "param")>

                       <cfreturn variables.dao.count(param=arguments.param)>

                <cfelse>

                       <cfreturn variables.dao.count()>

                </cfif>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during count: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during count: " & cfcatch.message >

                       </cfif>

                       <cfthrow message="#msg#">

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during count: " & cfcatch.message >

                       <cfthrow message="#msg#">

                </cfcatch>

         </cftry>

  </cffunction>

 

 

  <cffunction name="doCreate" access="private" output="no">

         <cfargument name="co" required="yes" hint="The change object.">

 

         <!--- the record to create --->

         <cfset var new = co.getNewVersion()>

 

         <!--- TODO: Validate that all the required fields are set --->

 

         <cftry>

                <!--- create the record, create returns with the identity fields set --->

                <cfset variables.dao.create(new)>

                <!--- set the new version in to the change object --->

                <cfset co.setNewVersion(new)>

                <!--- mark this change as processed successfully --->

                <cfset co.processed()>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during create: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during create: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during create: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <cfreturn co>

 

  </cffunction>

 

  <cffunction name="doUpdate" access="private" output="no">

         <cfargument name="co" required="yes" hint="The change object.">

 

         <!--- the record to update --->

         <cfset var new = co.getNewVersion()>

         <cfset var old = co.getPreviousVersion()>

 

         <cftry>

                <!--- update the record --->

                <cfset new = variables.dao.update(old, new)>

                <!--- mark this change as processed successfully --->

                <cfset co.processed()>

 

                <!--- If there was a conflict, mark the change object.

                      Include the current version of the record --->

                <cfcatch type="conflict">

                       <cfset co.conflict(variables.dao.read(id=new.getid()))>

                </cfcatch>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during update: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during update: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during update: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <cfreturn co>

 

  </cffunction>

 

  <cffunction name="doDelete" access="private" output="no">

         <cfargument name="co" required="yes" hint="The change object.">

 

         <!--- the record to delete --->

         <cfset var old = co.getPreviousVersion()>

 

         <cftry>

                <!--- delete the record --->

                <cfset variables.dao.delete(old)>

                <!--- mark this change as processed successfully --->

                <cfset co.processed()>

                <!--- If there was a conflict, mark the change object.

                      Include the current version of the record --->

                <cfcatch type="conflict">

                       <cfset arr = variables.dao.read(id=old.getperson_id())>

                       <cfset co.conflict(arr[1])>

                </cfcatch>

 

                <!--- If the SQL failed, report the error, include SQL if debugging turned on --->

                <cfcatch type="database">

                       <cfif isDebugMode() AND  isDefined("cfcatch.queryError") AND isDefined("cfcatch.sql")>

                              <cfset msg = "Error during delete: " & cfcatch.queryError & ". SQL was :" & cfcatch.sql>

                       <cfelse>

                              <cfset msg = "Error during delete: " & cfcatch.message >

                       </cfif>

                <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

                <!--- If anything else happened, report the error --->

                <cfcatch type="any">

                       <cfset msg = "Error during delete: " & cfcatch.message >

                       <!--- Make sure to mark the change with an error --->

                       <cfset co.fail(msg)>

                </cfcatch>

         </cftry>

 

         <!--- Return the change object --->

         <cfreturn co>

 

  </cffunction>

</cfcomponent>

 

10.   FB4创建一个Coldfusion+LCDSProject,命名为Flex2006,新建一个测试mxml,命名为flex2004.mxml

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

               xmlns:s="library://ns.adobe.com/flex/spark"

               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <s:layout>

        <s:BasicLayout/>

    </s:layout>

    <fx:Script>

        <![CDATA[

            import mx.collections.errors.ItemPendingError;

            private function createPendingItem(index:int, ipe:ItemPendingError):Object {

                return "[" + index + " ...]";

            }

            private function createFailedItem(index:int, info:Object):Object {

                return "[" + index + " failed]";

            }

        ]]>

    </fx:Script>

    <fx:Declarations>

        <!-- 将非可视元素(例如服务、值对象)放在此处 -->

        <s:DataService destination="workcalendar" id="ds"/>

        <mx:ArrayCollection id="products"/>

    </fx:Declarations>

    <s:SkinnableContainer>

        <s:layout>

            <s:VerticalLayout>

            </s:VerticalLayout>

        </s:layout>

        <s:Button label="Get Data" click="ds.fill(products);"/>

        <mx:DataGrid dataProvider="{products}" id="dg">

        </mx:DataGrid>

    </s:SkinnableContainer>

    </s:Application>

 

注意编译选项 -services "CF_wwwroot/WEB-INF/flex/services-config.xml" -locale en_US

 

 

 

11.   workcalendar.cfcworkcalendarAssembler.cfcworkcalendarDAO.cfcworkcalendar.as拷贝到CF_wwwroot/com/les/visual目录下面。

12.   运行结果。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值