CFAjaxProxy – dos and don’ts

Further to Friday’s post regarding my issue with CFAjaxProxy and getter / setter methods this reason for the failure to persist the variables set was neatly explained by Andrew Scott, both in the comments on this blog, via twitter and in more detail on a post on his own blog.

I’ve been thinking about this over the weekend and have come up with the following rules (suggestions for anyone else, rules for my own development) to work with CFAjaxProxy in the future:

  • Don’t – expose your normal CFC’s to remote access. This goes without saying to be honest but there’s a load of code that simply won’t work in the AJAX model and you don’t really want your entire interface exposed to remote calls therefore:
  • Do – create a new access layer for your AJAX calls – this can then (safely) call the other CFCs in your project without exposing their methods and you can neatly contain all of the AJAx specific funniness without having to rework or over complicate your business layer.
  • Do – create getter and setter method for arguments in your AJAX layer. It will enable you to use them in normal server side execution and will encourage good coding practices but…
  • Do – duplicate your setter logic in the head of each method. I appreciate this goes against the principles of DRY but will ensure you can pass in your globals and persisted data when calling over AJAX. A bit of clear logic will allow this code to co-exist with Getters and Setters and ensure your code remains a flexible as possible
  • Do – look into and understand the singleton approach to using a CFC with persisted data
  • Don’t – be tempted to use session storage for your remote CFCs without truly understanding the risks and the possibilities for collision.

There are probably many, many more but this is the start of a list of good practice from a truly new CF developer. Got some good Remote ColdFusion tips or procedures that have saved your bacon? Please share!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s