Products

Products
Viewing By Entry / Main
October 16, 2008

Coldbox Framework and Ajax: cfajaxproxy

After working in Coldbox for a while I know your first instinct is to make a cfajaxproxy call to a cfc event just like all the other Coldbox events. However, using cfajaxproxy is just a little different. Here is an example to show you one simple way of doing it, not the only way but one of them.

First let me note that I am using Coldspring version of IOC. It should work the same though with any form of IOC. Mostly we need the IOC to provide the bean to the services your Ajax call requires from within the Coldbox proxy.

After having provided a service in Coldspring like so:

<bean id="usersService" class="model.usersService">
<constructor-arg name="privatemessagesGateway">
<ref bean="privatemessagesGateway"/>
</constructor-arg>
<constructor-arg name="ColdBoxController">
<ref bean="ColdBoxController"/>
</constructor-arg>
</bean>

we can use this "usersService" bean in the coldboxproxy.cfc like this:

<cffunction name="ajxSetPMRead" access="remote" output="false" returntype="void">
      <cfargument name="messageid" type="String" required="true"/>
      <cfset var pm = getBean('usersService').getPrivateMessageByID(int(arguments.messageid))>
      <cfset pm.setRead(1)>
      <cfset getBean('usersService').savePrivateMessage(pm)>
   </cffunction>

The code above is what the Ajax, cfcajaxproxy, will call as a method for Coldbox to perform. It fetches a private message object bean, sets or updates some properties, then uses the gateway to save the object bean. I don't have a return or output but you can do that also here if desired. And here is the actual view and Ajax calling code:

<cfajaxproxy cfc="coldboxproxy" jsclassname="cbProxy">

<a href="##" onClick="showMessageDetails('#privateMessagesQuery.privatemessageid#','#privateMessagesQuery.read#','#privateMessagesQuery.subject#','#privateMessagesQuery.fromUserName#','#privateMessagesQuery.message#')">#privateMessagesQuery.subject#</a>

<$cript>
function showMessageDetails(messageid,read,subject,from,message){
   var e = new cbProxy();
   if(read == 0){
      e.setCallbackHandler(setPrivateMessageRead);
    e.setErrorHandler(ajaxErrorHandler);
    e.ajxSetPMRead(messageid);
   }
   document.getElementById('pmReply').style.display = "none";
   document.getElementById('pmDetails').style.display = "inline";
   document.getElementById('pmDetails_Subject').innerHTML=subject;
   document.getElementById('pmDetails_From').innerHTML=from;
   document.getElementById('pmDetails_Message').innerHTML=message;
}
var setPrivateMessageRead = function(res){
   alert('set to read');
}
var ajaxErrorHandler = function(statusCode, statusMsg){
   alert('Status: ' + statusCode + ', ' + statusMsg);
}
</script>
The cfc attribute is dot notation to the location of your coldboxproxy.cfc, mine here is at the root. Basically I'm showing the private message details in a div but needing to set the read flag in the database to 1 to indicate it has been read. And using Ajax I can set this in the database for each message read without a page refresh. The alerts in the javascript are for demonstration and testing purposes.

The code I provided is a cut down version of actual code and does not include the view event, form code, queries, or other behind the scenes code. I hope this helps to give you a step ahead on how to use Ajax with the Coldbox framework.

Comments

[url=http://handbags.bz]replica bags[/url]
[url=http://handbags.bz]bags knockoff[/url]
[url=http://handbags.bz]chanel handbags[/url]
[url=http://handbags.bz]chanel handbags replica[/url]
[url=http://handbags.bz]replica handbags[/url]
[url=http://handbags.bz]Louis Vuitton Handbags[/url]
[url=http://handbags.bz]Louis Vuitton Handbags replica[/url]

<a href="http://handbags.bz">replica bags</a>
<a href="http://handbags.bz">bags knockoff</a>
<a href="http://handbags.bz">chanel handbags</a>
<a href="http://handbags.bz">chanel handbags replica</a>
<a href="http://handbags.bz">replica handbags</a>
<a href="http://handbags.bz">Louis Vuitton Handbags</a>
<a href="http://handbags.bz">Louis Vuitton Handbags replica</a>

replica bags, purse, replica handbags, bags knockoff, louis vuitton, chanel handbags, Gucci.


[url=http://www.yesgift.us/]replica purses[/url]
[url=http://www.yesgift.us/]knockoff purses[/url]
[url=http://www.yesgift.us/]chanel handbags[/url]
[url=http://www.yesgift.us/]replica handbags[/url]
[url=http://www.yesgift.us/]replica watches[/url]
[url=http://www.yesgift.us/]Rolex watches replica[/url]
[url=http://www.yesgift.us/]Louis Vuitton Handbags[/url]
[url=http://www.yesgift.us/]Louis Vuitton Handbags replica[/url]

<a href="http://www.yesgift.us/">replica purses</a>
<a href="http://www.yesgift.us/">knockoff purses</a>
<a href="http://www.yesgift.us/">chanel handbags</a>
<a href="http://www.yesgift.us/">replica handbags</a>
<a href="http://www.yesgift.us/">replica watches</a>
<a href="http://www.yesgift.us/">Rolex watches replica</a>
<a href="http://www.yesgift.us/">Louis Vuitton Handbags</a>
<a href="http://www.yesgift.us/">Louis Vuitton Handbags replica</a>



Please check out our website:
<a href="http://www.yesgift.us/">http://www.yesgift.us/</a> There are top quality of replica handbags for sell
with perfect weight, feel, and like the originals.or email us : info@fashionhause.com
yesgift offers wholesale Louis Vuitton and wholesale Chanel replica purses, wallets, and

handbags. Our products are made with the utmost attention to detail and can be a great addition

to your inventory of products. Our wholesale Louis Vuitton replica bags and purses are made to

be functional, durable as well as attractive. Similarly our line of wholesale Chanel replicas

are also feature high quality materials and craftsmanship.yesgift


[url=http://handbags.bz]Replica bags[/url]
[url=http://handbags.bz]Knockoff purses[/url]
[url=http://handbags.bz]chanel handbags[/url]
[url=http://handbags.bz]Replica handbags[/url]
[url=http://handbags.bz]Bags knockoff [/url]
[url=http://handbags.bz]Rolex watches replica[/url]
[url=http://handbags.bz]Louis Vuitton Handbags[/url]
[url=http://handbags.bz]Louis Vuitton Handbags replica[/url]

<a href="http://handbags.bz">Replica bags</a>
<a href="http://handbags.bz">Knockoff purses</a>
<a href="http://handbags.bz">chanel handbags</a>
<a href="http://handbags.bz">Replica handbags</a>
<a href="http://handbags.bz">Bags knockoff</a>
<a href="http://handbags.bz">Rolex watches replica</a>
<a href="http://handbags.bz">Louis Vuitton Handbags</a>
<a href="http://handbags.bz">Louis Vuitton Handbags replica</a>

[url=http://handbags.bz]Burberry shoes[/url]
[url=http://handbags.bz]Celine shoes[/url]
[url=http://handbags.bz]Chanel shoes[/url]
[url=http://handbags.bz]Dior shoes[/url]

<a href="http://handbags.bz">Burberry shoes</a>
<a href="http://handbags.bz">Celine shoes</a>
<a href="http://handbags.bz">Chanel shoes</a>
<a href="http://handbags.bz">Dior shoes</a>



Copyright © 2005-2006 Clint Willard. All rights reserved.
Aura skin for Clint Willard's BlogCFC inspired by Brooks Bilson's Bolg.
All trademarks property of their owners.