Finally! Ok you can now download an alpha release of Bender:
Bender Alpha 01 (Bender_alpha01.zip)
Please bear in mind this is a first release, and while it works for me your mileage may vary wildly. I would really appreciate hearing from anyone who had time to try this out, and has bugs, suggestions, corrections or criticisms.
Download the zip file, and expand it into your webroot, or somewhere that a cf mapping points to as “com”. You shouldn’t need to setup anything specific for flex, it will just use the default flash remoting adapters.
The following steps should get you up and running with Bender:
- Make sure Transfer release 0.6.3 or higher is installed and working
- Make sure /com points to the com directory from the bender zip file
- Browse to http://yourserver/com/ls/bender/tools/BenderClassGenerator.cfm
- Change the paths to match your settings and submit the form – this will create an actionscript class file for each definition in your Transfer.xml
- I haven’t made the auto compiled swc bit yet, so for the moment, make sure you drop these class files into your flex application, along with com/ls/bender/as/Bender.as and import them in your code
- In your flex code you can now run operations like: bender.read(oUser, “User”, userPK);
Operations:
bender.read(Class class, String TransferClassName, String primaryKey);
The first parameter for a read is an already instantiated object – one of the classes bender generated for you. You pass this in, and when the read is complete the object will contain the relevant data.
The second parameter is the name of the object definition – the “class” attribute in your Transfer.xml
The third is the unique identifier you’d normally use to retrieve that object via transfer.
make whatever changes you like to the data in the As objects then use:
bender.save(Class class);
just pass in the actionscript instance and this will automatically save back to the db.
MAPPINGS
You can map functions to a custom CFC if you choose. For example, if you wanted a UserManager.cfc to do something with the user objects before they went to Transfer for saving, you could create a Bender.xml like so:
<?xml version="1.0" encoding="UTF-8"?>
<bender>
<mappings>
<mapping action="save" mapobject="UserManager" mapmethod="save" />
</mappings>
</bender>
This will mean that when you use bender.save(myObj) in flex, the data will go to Bender on the coldfusion side and get translated into an appropriate TransferObject which will then be passed on to UserManager.save(TO). If you don’t create a mapping for a particular method and class, it defaults to sending straight to Transfer.
CAVEATS:
I had some issues in actionscript using methods named get and delete, so in Bender you call bender.read() and bender.del() instead. This may be something I did wrong and if so I’ll fix it – but for the moment that’s how it works.
Delete works the same way as save.
EVENTS
When you have instantiated one of the bender-generated actionscript classes, you can set oMyObj.OLNDATA() and oMyObj.ONFAULT() to provide functions to which Bender will map upon data population or fault. For example, if you want a message shown to the user when you save something, you could do this:
public function showResults(obj : *) : void {
result_text.text = "Save Successful";
}
public function showFailure(obj : *) : void {
result_text.text = "Save Failed";
}
oObj.ONDATA(showResults);
oObj.ONFAULT(showFailure);
bender.save(oObj);
Please download the code and take a look – and I’d love to hear from anyone on ways to improve it. Let me know what works and what doesn’t and contact me on this blog or on skype / icq / email etc etc.
P.S. I haven’t added the SWC generation yet, but am working on it now and hopefully that will make integration of auto-generated as classes and the bender code into your flex app much easier. If anyone has any preferences or suggestions for this bit, please let me know.
Tweet This Post