Learning ColdBox: Coldbox Proxy How Cool is This!

I had some CFGRID code I needed to implement into an existing ColdBox application. The grid run out of the box without any intervention from the ColdBox Framework. However it would be necessary for the CFGRID to access my service layer and properties injected from ColdSpring if I wanted it to take full advantage of the CB Framework. I assumed this would be a nightmare, I mean how to I get my AJAX grid to use the same reusable ColdBox and model code?

With ColdBox Proxy of course! The ColdBox proxy enables remote calls like AJAX to communicate with ColdBox and take advantage of all the goodies it has to offer, thanks ColdBox!

So how easy was it to get working? Very, it only took a few extra lines of code to work, really!

First I told my CFGRID to access the proxy directly and not the CFC.

   view plainprintabout
 bind="cfc:admin.coldboxproxy.getAllproducts({cfgridpage},
  {cfgridpagesize},
  {cfgridsortcolumn},
  {cfgridsortdirection})"

Next using the ColdBox proxy template already provided (which extends coldbox.system.extras.ColdboxProxy) I created a new function that works the same was as handlers in ColdBox.

   view plainprintabout
 <cffunction name="getAllproducts" output="false" access="remote" returntype="any" hint="Process a remote call and return data/objects back.">
  <cfargument name="page" type="numeric" required="yes">
  <cfargument name="pageSize" type="numeric" required="yes">
  <cfargument name="gridsortcolumn" type="string" required="no" default="">
  <cfargument name="gridsortdir" type="string" required="no" default="">
 
  <cfset var results = "">
  <cfset results = getBean("storeService").getAJAXProducts(page=#arguments.page#,                     pageSize=#arguments.pageSize#,
             gridsortcolumn=#arguments.gridsortcolumn#,
10              gridsortdir=#arguments.gridsortdir#) /
>

11  
12   <!--- Convert Query for Paging --->
13   <cfreturn QueryConvertForGrid(results,page,pageSize)>
14  </cffunction>

getBean("storeService") interact directly with the service layer. Once this was done I could then take advantage of my dependency injection framework and ColdBox features. How cool is that!

Related Blog Entries

TweetBacks
Comments
 

About Me

Glyn Jackson, 27 years old, MD and senior developer of a development firm based in Staffordshire called Newebia Ltd. Academic background in BSc Information System & Internet Commerce. Online marketing expert (EE Ranked) and .NET developer. Has been developing with ColdFusion for 5 years and loves it. "I am not a veteran in ColdFusion but I do work on challenging projects which help me learn more about ColdFusion and if I can contribute to the community in anyway then, it's all good!"

Recommends

  • ColdFusion