Tải bản đầy đủ - 0 (trang)
Lesson 21. Synchronizing Data with Adobe Flex Data Services

Lesson 21. Synchronizing Data with Adobe Flex Data Services

Tải bản đầy đủ - 0trang

StartingFiles:

Lesson21/start/DMS_2.mxml

CompletedFiles:

Lesson21/complete/DMS_1.mxml

Lesson21/complete/DMS_2.mxml

Lesson21/complete/valueObjects/SmallProduct.as

(createdbyFlexBuilderCFCWizard)

Lesson21/complete/flex2tfs/dmsCFCs/SmallProduct.cfc

(createdbyFlexBuilderCFCWizard)

Lesson21/complete/flex2tfs/dmsCFCs/SmallProductAssembler.cfc

(createdbyFlexBuilderCFCWizard)

Lesson21/complete/flex2tfs/dmsCFCs/SmallProductDAO.cfc

(createdbyFlexBuilderCFCWizard)

ThislessonwillintroduceyoutotheFlexDataServices'Data

ManagementService,andexplainhowtouseittosynchronize

databetweenclientandserver.Keepinmindthatthisisan

introductiononlyitwouldtakemanytimesthenumberofpages

inthislessontofullyexplorealltheamazingfeaturesofthe

DataManagementService.Inthefewpagesinthislesson,you

willseehowtoharnesssomeofthepowerfulfeatureswhen

usingFlexDataServices2andColdFusiontogether.

FlexDataServicesautomaticallypropagatesachanged

DataGridcontroltoedittheremotedatastore.



[Viewfullsizeimage]







IntroducingtheDataManagementService

AdobeFlexDataServices2(FDS)providestheData

ManagementServicethatassistsindatasynchronizationand

datareplicationbetweentheFlexfrontendandyourbackend.

ThebackendcouldbewritteninJavaorColdFusion,for

example.Inthislesson,youwilluseColdFusionandtake

advantageofsomewizardsbuiltintoFlexBuilderthat

automaticallycreatetherequiredColdFusioncomponents

neededfortheDataManagementService.

TheDataManagementServicegreatlyeasesyourworkwhen

you'recreatingapplicationsthatusedistributeddata.AclientsideDataServicecomponent,instantiatedinMXMLor

ActionScript,callsmethodsonaserver-sidedestinationto

performsuchactivitiesasprovidingdatatoclient-sidedata

collectionsandsynchronizingchangesattheclienttothe

server.Noticethesentencesaidthe"DataServicecomponent,"

not"youthedeveloperwritingcode,"callsmethods.The

DataServicecomponentmanagesdataattheclient,andthe

DataManagementServicemanagesthedistributionofdata

amongmultipleclientsandtheserver-sidedataresources.

AkeyfactorinsuccessfullyimplementingtheDataManagement

Serviceisproperconfiguration.Toconfiguretheservice

properly,youneedtoknowthevocabularyinvolvedwiththe

technology.

Thefirsttermtounderstandisadestination.Adestinationisan

endpointforamessage(data)wherethemessagewillbeacted

upon.Destinationsareconfigurableinthedata-managementconfig.xmlfile.WhenconfiguringasimpleColdFusion

destination,youspecify,amongotherthings,adestination

name,theColdFusioncomponent(CFC)wheremethodrequests

aresent,andtheprimarykeyvalueofthedatabasetablethe

CFCisworkingwith.



Anotheritemspecifiedinthedestinationisthemessage

channelthatthedestinationshouldusetocommunicate.The

messagechannelsarepartoftheoverallFlexmessaging

service.PossiblechannelstouseareActionMessageFormat

(AMF),HTTP,secureAMF,secureHTTP,andReal-Time

MessagingProtocol(RTMP).Thebasiccommunicationmodelof

theDataManagementServiceisshowninthefollowing

example:



Whenamessagehitsthedestinationontheclientside,itis

processed.Ontheserverside,theDataManagementService

ofteninteractswithadatastore.

ThedataadaptercontrolshowFlexDataServicesworkswitha

particularinterface,likeaCFCorJavaobject.Thedataadapter

updatesthepersistentdatastore.Bydefault,threeadapters

areincludedwithFlexDataServices:theJavaadapter,the

ActionScriptadapter,andtheHibernateadapter.AColdFusion

adaptercanbeusedsimplybyinsertingitinaconfiguration

file,whichyouwilldointhefirsttaskinthislesson.

Onceconfigured,youcanthenusemethodsoftheDataService

objecttosynchronizedatabetweentheFlexclientandtheback

end.



[Viewfullsizeimage]







ConfiguringDataManagementServices

Thefollowingconfigurationinstructionsassumeyouhave

installedthefollowingsoftwareaccordingtothesetup

instructionsincludedintheAppendix,"SetupInstructions":

FlexBuilder2

FlexDataServices

ColdFusion

ColdFusionExtensionsforFlexBuilder2

YouwillmakechangestotwofilestoconfigureFlexData

ServicestoworkwiththeDataManagementServiceusing

ColdFusionasthebackend.



Caution

Youmustbeverycarefulwhenmakingchangestothese

files.Onemistakeorcommentinthewrongplacecan

causeFlexDataServicestonotstart.



FlexDataServicesprovidestheexactcode,oratleasta

template,foryoutouseduringconfiguration.Thefiles

containingtheconfigurationhelpareinthedirectory

driveroot/fds2/resources/config.Inthistask,youwillbe

copyingdatafromfilesinthisdirectoryandpastingitintothe

actualconfigurationfilesinthefolder



driveroot/fds2/jrun4/servers/default/flex/WEB-INF/flex.

1. Locatethedriveroot/fds2/jrun4/servers/default/flex/WEB-INF/flex

directory.Makecopiesofthefollowingfiles:

services-config.xml

data-management-config.xml



Bymakingcopiesofthetwofilesyouwillbemodifyinginthenextstep

thistask,youhavetheoriginalstorefertoifsomethingshouldgowro



2. BesurethatFlexDataServicesisnotrunning.Openthefileservicesconfig.xmllocatedindriveroot/fds2/resources/config.Locatethetwo

channeldefinitionsfromlines137160thatarecommentedas

specificRTMPchannelandColdFusionspecificHTTPchannel.Copythisblocko

code:




class="mx.messaging.channels.RTMPChannel">


class="flex.messaging.endpoints.RTMPEndpoint"/>



20





false










class="mx.messaging.channels.AMFChannel">




{server.port}/{context.root}/messagebroker/cfamfpollin

class="flex.messaging.endpoints.AMFEndpoint"/>







false



true

8




ThisXMLenablesthesemessagechannelsthatwillbeusedwhen

configuringColdFusiondestinations.



3. Openthefileservices-config.xmlfromthe

driveroot/fds2/jrun4/servers/default/flex/WEB-INF/flexdirectory.Loca

thetagthatENDSthechannelsnodeoftheXML,.Pastethe

copiedblockofcodejustABOVEtheclosingtag.,



Youhavemovedthechannelconfigurationsyouneedfromthe"helper

totheactualconfigurationfile.



4. Openthefiledata-management-config.xmlfromthe

driveroot/fds2/jrun4/servers/default/flex/WEB-INF/flexdirectory.Youw

seeannode.AddthefollowingasthelastlineofXMLinthe


class="coldfusion.flex.CFDataServicesAdapter"/>

ThisdefinestheadapterthatwillbeusedwithColdFusion.

5. Besureyouradaptersnodeappearsasfollows:






class="flex.data.adapters.ASObjectAdapter"default="tr


class="flex.data.adapters.JavaAdapter"/>


class="coldfusion.flex.CFDataServicesAdapter"/>



ThisenablestheadapterthatyouwillusewithColdFusion.



6. Openthefiledata-management-config.xmlfromthedirectory

driveroot/fds2/resources/config.Locatethedestinationdefinitionfrom

288395thatiscommentedasColdFusionSample-Contactsampleapplicatio

Copythisblockofcode.Besureyougettheentiredestinationdefinitio

markedbytheandtags.



Thisdefinesadestinationforasampleapplication,butnotforwhatyo

need.Afteryoupastethecodeintothecorrectlocation,youwillmodif

XMLfortheapplicationyouarebuildinginthislesson.



7. Openthedata-management-config.xmlfilefromthe

driveroot/fds2/jrun4/servers/default/flex/WEB-INF/flexdirectory(you

addedanadapterdefinitiontothisfileinstep4).Pastethedestination

definitionyoujustcopiedBELOWtheclosing
andABOVEthe

closingtag.g



Youhavemovedadestinationdefinitionyouneedfromthe"helper"fil

theactualconfigurationfile.Youwillnoweditthedestinationdefinition

containstheinformationfortheapplicationyouarebuildinginthisles

8. Changethecommentatthetopofthedefinitionasshown:









Thecommentnowreflectstheuseofthedestination.



9. Justbelowthecomment,changetheidofthedestinationsoitisequa

flex2tfs:





WhenyoucreateaDataServiceobjectinyourMXML,youwillusethis

value.

10. Inthepropertiesnode,changethecomponentvalueto

flex2tfs.dmsCFCs.smallProductAssembler:



flex2tfs.dmsCFCs.smallProductAssembler


TheCFCindicatedwillbecreatedautomaticallybyawizardandactsa

frontendtocodethatwillupdatethedatastore.

11. Locatethemetadatanode,andchangethepropertyattribute'svalueto







Thisdefinestheprimarykeyvalueofthedatabasetable.



12. Saveboththedata-management-config.xmlandservices-config.xmlfi

andthenclosethem.



TheseconfigurationfileswillbeusedwhenyoustartFDS.



13. StartFlexDataServicesbyopeningaconsolewindow(DOSprompt)a

movingtothedriveroot/fds2/jrun4/bindirectory.Thenenter

default.BesureFDSstartswithnoerrorsbeingshown.Tostopthe

service,usetheCtrl+Ckeycombination,orclosetheconsolewindow.

restarttheservice,ifyouarestillintheconsole,justpresstheuparro

anditwillbringbacktothepromptwhatyoupreviouslytyped.



YouwillneedtoleavetheconsolewindowopenwhenyouareusingFD

FDSwillonlyberunningwhiletheconsolewindowisopen.



14. StarttheconfiguredColdFusionbyopeninganotherconsolewindow(D

prompt)andmovingtothedriveroot/cfusion/bindirectory.Thenenter

startcfusion.BesureColdFusionstartswithnoerrorsbeingshown.

stoptheserviceusetheCtrl+Ckeycombination,orclosetheconsole

window.Torestarttheservice,ifyouarestillintheconsole,justpress

uparrowanditwillbringbacktothepromptwhatyoupreviouslytype

Youwillneedtoleavetheconsolewindowopenwhenyouareusing

ColdFusion.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Lesson 21. Synchronizing Data with Adobe Flex Data Services

Tải bản đầy đủ ngay(0 tr)

×