How to retrieve a bean in ColdboxProxy.cfc?

Hello,

I do an ajax call to coldboxProxy.cfc. In process() I do a call to getModel(“beanname”) (where “beanname” is an existing bean) to retrieve a bean but insted I get an 500 error (I see it in Firebug). The Coldbox.cfc coldboxproxy.cfc is extending (coldbox.system.remote.ColdboxProxy) only has a private getModel() function. Changing the access attribute’s value from “private” to “public” has no effect.

Here is my code:


[…]

This gives me a 500 error. When I do

<cfset local.utils=getBean(“utils”)>

I get a value - no error. so the problem is in the call to getModel(). I saw in the docs that Coldbox 3.1 has a function getBean() that apparently does exactly what I want but I am not on that version.

Questions:

1 What is the equivalent to getBean() in my current version (3.0 ) of coldbox?

2 How canI detrmine the current version of Coldbox? I couldn’t find a getVersion() or equivalent while searching the /Coldbox/system base…

Marc

Not sure about ColdBoxProxy as I don’t use it, especially when using Ajax calls. Is there any reason you are using the proxy for Ajax?

I want to make an Ajax call from my webapp… I figured that one should use the coldboxproxy to process these. Am I wrong here?

Not really, but you are better of doing something like this

// Basic request in jQuery
$.ajax({ type: , url: , data: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); } });
Ext.Ajax.request({ url: ‘/handler/action/’, params: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); }});

Depending on your needs, or how you are calling the Ajax will depend on how the handler gets the data. Especially if you are doing Rest type calls.

Marc,

ColdBox has the ability to return JSON from an event handler.

Event.renderData(data={complex data},format=‘JSON’).

This allows your normal application lifecycle to work but to support AJAX interfaces,

-A

Hmm.

I copied /ColdboxProxy.cfc to /handlers and renames it remoteProxy.cfc
I change the extends attribute value from

coldbox.system.remote.ColdboxProxy
to
coldbox.system.eventhandler

I kept the process() function the same:

I change the url in my JQuert .ajax call from call from
http://zencms.eenschoolintogo.local/coldboxProxy.cfc?method=process

to

http://zencms.eenschoolintogo.local/handlers/remoteProxy.cfc?method=process

When I do a .Ajax call:

$.ajax({
url: CBProxyURL,
type: ‘GET’,
data:{
emailBody: formData,
event: ‘sendEmail’
},
[…]

I see in Firebug variable I get a 500 error with this text in columnn ‘status’:
“Variable CONTROLLER is undefined”

When I do

in process() it gives me a dump of the function.

Seems like calling the framework this way bypasses something?

Marc

No, forget the notion of what you are doing Marc.

Write it as a normal handler, and then call it from jQuery as if you are calling it from the URL. Like I showed you.

// Basic request in jQuery
$.ajax({ type: , url: , data: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); } });
Ext.Ajax.request({ url: ‘/handler/action/’, params: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); }});

So in case you forgotten how to write a handler

handler test.cfc

component {

public void myAction(event) {
}
}

Would be called like this

// Basic request in jQuery
$.ajax({ type: , url: , data: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); } });
Ext.Ajax.request({ url: ‘/test/myAction/’, params: { foo: ‘bar’ }, success: function(msg){ alert( + msg ); }});

I am assuming two things here, you are using SES and cfscript. If not then write it as tags, and write the URL in the Ajax call the same as if you are writting it in the url.

so that means I could in my browser address bar write

http://mydomain/test/myAction/datakey/dataValue

and in Ajax that would be

Ext.Ajax.request({ url: ‘/test/myAction/’, params: { datakey: ‘dataValue’ }, success: function(msg){ alert( + msg ); }});

Enjoy…

@Andrew - just out of curiosity why don't you use the coldproxy for ajax calls?

Because its a level that is not required. All you are doing is adding extra process running for no real benefit.

+infinity

@West,

There could be an advantage in using a remote proxy. When you create a remote proxy, ColdFusion creates a new instance of that CFC and executes the remote method. You have the ability to really change the behavior of the request when doing this. But, if your normal life cycle works for you with all the event handlers, interceptors etc… executing as they normally would then your just creating an additional entry point with more to maintain/debug going forward.

I do still use the remoteproxy from time to time, but, most ajax/api work goes straight to an event handler as Andrew suggested.

-Aaron

Thanks, its working now.