LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle...

34
LiveCycle Data Services Introduction Part 2

Transcript of LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle...

Page 1: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

LiveCycle Data Services Introduction

Part 2

Page 2: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Part 2?

• This is the second in our series on LiveCycle Data Services. If you missed our first presentation, it can be found at:– http://www.theFlexGroup.org/presentations.cf

m

• Last time, we covered what LDS is, and some on LDS Messaging

Page 3: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• Data Management is the component of the LiveCycle Data Services suite of services that allows for LDS to help you communicate and control the data to your end user

• Allows for Data Synchronization, Data Caching, Data Pagination, and Conflict Resolution.

Page 4: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

How it works:• Data is packaged up

into ‘Value Objects’, or packages of data.– This usually consists

of a “row” of data from a database

• Each VO is tracked separately as to who is viewing, editing, etc.

Page 5: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• Users then Subscribe to a set of data.– LDS will then keep track

of the state of that data, and send it from the Application Server to the Flex Application.

• LDS will ‘listen’ to any changes made to the data in the Flex Client.

Page 6: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• If the Collection that holds the data is changed in the client, LDS will take that change, change the Value Object in memory, send the change to the App server, and update all clients in real-time.

Page 7: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• When an update is sent to the other clients, it will check its local copy, to make sure that record has not changed. If it has, it will issue a “Conflict” event, and allow the Client to choose what to do.

Page 8: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• On the Client, 95% of your work is handled by any of the Collection classes, such as the ArrayCollection

• Handles updating LDS with Changes, and notifying other visual components of changes.

Page 9: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Data Management

• When a DataGrid, or InputBox broadcast the Change event, the ArrayCollection hears it, and updates its own data, and passes the change to other components that subscribe to its change event.

Page 10: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an Application

• We will be building a quick “CMS” application utilizing a simple DataGrid and some buttons…– Backend will be ColdFusion and Microsoft

Access– LiveCycle 2.5 will be used– Flex SDK 2.0.1 will be used inside Flex

Builder 3 beta 2.

Page 11: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• First, we will want to create a new database file in Access. We will be using the “Contacts” template to create the file.– Normally, we would create a custom database

file for this purpose.– If using Access 2007, make sure to save the

file as an Access 2003 or Access 2000 file.

Page 12: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Next, we will want to add the new Database as a ‘Datasource’ in ColdFusion– Named “ug_contacts”, using the Access

Unicode Driver

• Load up Flex Builder, and create a new Flex Project– Web Application, ColdFusion App Server,

LiveCycle Data Services

Page 13: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Create a new folder on the server for the ‘Value Objects’, \bin\cfcs\

• Create a new AS Class folder : \src\ascript

• Open the RDS view, and find the Contacts table

• Right-Click on Table, ColdFusion Wizards, Create CFC

Page 14: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• CFC Folder:– /contact_cms/bin/cfcs

• CFC Package Name:– contact_cms-debug.cfcs

• CFC Type:– LiveCycle DS Assembler

• Create AS-VO– AS Folder: \src\ascript

Page 15: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Next, we need to modify the LDS configuration files to tell LDS about the components we just created.– File is in the wwwroot\WEB-INF\Flex\

directory, named data-management-config.xml

• Add a new entry (Destination) to represent the component we just created.

Page 16: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Destination.properties.component– Component dot path on the CF server

• Destination.properties.scope– Application or request

• Destination.properties.metadata.identity– Set this to the key field in your table

• Destination.properties.metadata.query-row-type– This is the path to the ActionScript Value Object

we created.

Page 17: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Restart LiveCycle Data Services, and make sure there are no errors– If using the bundled LDS with ColdFusion,

restart the CF Application Service

• Now, we just need to create the client, and we are done!

Page 18: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Open your MXML document, and add a <mx:DataService> tag– Give it an ID, and the Destination that we

used in the last step

• Add a new ArrayCollection variable (to hold your data)

• Add a new function to execute the DataService.fill(arrayCollection);

Page 19: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Building an App

• Next, add a DataGrid and at the very least, a button to trigger the fill() command.

• Bind this DataGrid to your ArrayCollection, and set the editable property to true.

• Also, open up the Contacts.as file, and notice the [Managed] metadata. This code tells the AS to broadcast its changes to outside components.

Page 20: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

RUNNING THE APPLICATIONConnect to http://kwiatk27.msu.edu:8500

Page 21: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Running the Application

• If you update the data in one application, the data becomes updated in any other instances of the Flex Client, in real time!

• What if you wanted to queue the changes, or allow the user to back out of the changes before they occur?

Page 22: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Turning off AutoCommit

• In order to allow the clients to queue changes, and control when they commit the changes, we need to turn off the AutoCommit feature of the DataService

• Add the autoCommit=“false” declaration to the DataService component.

• We will now need to add two buttons to allow the user to commit their changes.

Page 23: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Turning off AutoCommit

• Add two additional buttons:– Name one Apply, with a click event of :

dataService.commit();– Name the second Cancel, with a click event of

: dataService.revertChanges();

Page 24: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

AUTO-COMMIT DEMOhttp://kwiatk27.msu.edu:8500

Page 25: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Adding and Removing Items

• Adding and removing items to the database is as trivial as adding a new item to the ArrayCollection.– Remember when adding an item, you may

need to turn off the AutoCommit feature, as your database may not allow null values.

• ArrayCollection.addItem(new className());• DataService.deleteItem(dgContacts.selecte

dItem);

Page 26: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Conflicts

• Another nice thing about Data Management is the ability to have Conflict Resolution built right into your application.

• LDS can trigger an event when another user updates a record you are currently updating

• Add the “conflict” event handler to the DataService to create your own conflict handler.

Page 27: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Conflict

• When handling a conflict, you have the option to update with your version, take the server’s version, or to let the user choose what version to keep.

• Lets show how to detect a conflict in data sets, notify the end user, overwrite the client’s data with the server’s version.

Page 28: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

CONFLICT RESOLUTIONhttp://kwiatk27.msu.edu:8500

Page 29: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Fill Queries

• Using the ‘out of the box’ data management is great if you want to return full sets of data– But what happens if you want to return only a

portion of your full table; for example a search result?

• You can customize your fill parameters by modifying your assembler’s Fill() function and passing the fill as the second parameter of the call.

Page 30: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Fill Queries

• For example:– DataService.fill(ArrayCollection,SearchString:

string);

• Translates to:– <cffunction name=“fill”>

• <cfargument name=“searchString”…./>

– </cffunction>

Page 31: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Paging

• What happens if you have too much data returned from a query to send down to the clients?– For example, do you really want to send

50,000 records down the pipe?

• LDS has a built in Paging mechanism!

Page 32: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Paging

• To configure it, edit your data-management-config.xml file.– Destination.properties.network

• <paging enabled=“true” pageSize=“xxx”/>

• That is all you have to do!

Page 33: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

PAGING & QUERIEShttp://kwiatk27.msu.edu:8500

Page 34: LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,

Questions?

[email protected]