getFunctionCalledName() not supported?

72 views
Skip to first unread message

Mark Mandel

unread,
Dec 10, 2011, 1:17:01 AM12/10/11
to ra...@googlegroups.com
i was sure I read ages ago that getFunctionCalledName() was supported on Railo?

Since I'm getting errors when trying to use this function, I can only assume that it isn't.

Is there another way to get the function name from within a function, for when you are doing mixins?

Mark Drew

unread,
Dec 10, 2011, 7:24:20 AM12/10/11
to ra...@googlegroups.com
Yes, it was discussed a few days ago and I think there is a ticket related in Jira, I just can't think of it off the top of my head… so instead of giving you a fish, I am going to teach you how to fish! :)


If you go into your admin of http://<website>/railo-context/admin/web.cfm and log in, you will see on the left a 
Documentation - > Function Reference

there you will have a drop down and there will be some getCurrentContext() (or something like that) ?

Which gives you the current stack trace?

Hope that helps! 

MD

Mark Mandel

unread,
Dec 10, 2011, 7:50:56 AM12/10/11
to ra...@googlegroups.com

Thanks. I was sure this was implemented in Railo years ago, but it must have been my imagination.

I went looking for a Jira ticket, but couldn't find one. If there isn't one, I'll put one in.

Thanks for the pointer to the context method, I'll check it out.

Mark

Sent from my mobile doohickey.

Michael Offner

unread,
Dec 11, 2011, 7:27:42 PM12/11/11
to ra...@googlegroups.com
there is no ticket for this, feel free to open one.
the function getCurrentContext will not help, because it only returns a array of struct with template path and line number.
this will do the trick:
<cfset var udfName=getMetaData(getPageContext().getActiveUDF()).name>
BUT it only work inside a method (UDF inside a CFC). i have attached a complete example (including a example for "getCurrentComonentName").

/micha




2011/12/10 Mark Mandel <mark....@gmail.com>
getFunctionCalledName.zip

Mark Mandel

unread,
Dec 11, 2011, 7:56:13 PM12/11/11
to ra...@googlegroups.com
Oh sweet! Thank you very much.

Ticket created, and I attached your workaround file.

Mark

Mark Mandel

unread,
Dec 11, 2011, 7:56:25 PM12/11/11
to ra...@googlegroups.com

Mark Mandel

unread,
Dec 13, 2011, 2:42:22 AM12/13/11
to ra...@googlegroups.com
Michael, just tried your workaround, however, it doesn't work for mixins :( it just returns the original function name.

Which is where you need it the most.

Don't suppose you know a good workaround that will work for mixins off the top of your head? :)

I've updated the ticket below with my updated test case that shows that it doesn't work for mixins.

I'll have a dig around and see if anything is obviously useful too.

Mark


On Mon, Dec 12, 2011 at 11:56 AM, Mark Mandel <mark....@gmail.com> wrote:
https://issues.jboss.org/browse/RAILO-1670

There is the URL.

Mark

 
-- 

James Gibson

unread,
Jan 31, 2012, 1:22:28 PM1/31/12
to Railo
Any update on this issue? We are trying to use something similar
without success so far.

Thanks,
James

On Dec 13 2011, 2:42 am, Mark Mandel <mark.man...@gmail.com> wrote:
> Michael, just tried your workaround, however, it doesn't work for mixins :(
> it just returns the original function name.
>
> Which is where you need it the most.
>
> Don't suppose you know a good workaround that will work for mixins off the
> top of your head? :)
>
> I've updated the ticket below with my updated test case that shows that it
> doesn't work for mixins.
>
> I'll have a dig around and see if anything is obviously useful too.
>
> Mark
>
> On Mon, Dec 12, 2011 at 11:56 AM, Mark Mandel <mark.man...@gmail.com> wrote:
> >https://issues.jboss.org/browse/RAILO-1670
>
> > There is the URL.
>
> > Mark
>
> > --
>
> E: mark.man...@gmail.com

Michael Offner

unread,
Jan 31, 2012, 2:06:07 PM1/31/12
to ra...@googlegroups.com
We have partially implemented this function for Railo Appollo (4.0). But we still do not support the mixin part and to be honest we have no idea how to support this, the Railo architectur can not provide the name of the reference from where the function was called. This info is not coupeled with the function itself. For what exactly you need this info, perhaps I can help with a other workaround.

/micha

Vo mim iPhone gschickt

br...@bradwood.com

unread,
Jan 31, 2012, 2:55:27 PM1/31/12
to ra...@googlegroups.com
I can't speak for James, but WireBox (part of the ColdBox family) has been waiting on this functionality to have mixin support for ioc provider methods in Railo.

For instance, let's say I am concerned about widening the scope of an injected dependency, so instead I create a provider method will retrieve the dependency from the ioc container when I need it at run time.
Let's say the name of the provided object is UserService.  WireBox lets you do that with the following code:

component name="handler" singleton{
    function getUserService() provider="user"{}
}

The way WireBox achieves this is to replace the getUserService method with a generic provider mixin keeping the original name.  That generic method then uses getFunctionCalledName() when it is called to know what object it needs to retrieve when you call it.  The only other way around that would be to write a temporary CFM file at run time with the object name baked-in and then cfinclude it at run-time.

So, essentially, we need a pre-defined generic mixin method to be able to figure out the context in which it is being called with no arguments being passed into it so it can perform a specific task. 

References:

FWIT, this approach works great in ACF.

Thanks!

~Brad

James Gibson

unread,
Feb 9, 2012, 1:50:56 PM2/9/12
to Railo
I guess another way to implement this would be to allow a developer at
runtime to set metadata on a the type railo.runtime.type.UDFImpl. At
least I would then be able to set metadata about the function to later
reference and act accordingly.

If this is possible now, please let me know. I am still digging
through the railo source...

Thanks,
James



On Jan 31, 2:55 pm, <b...@bradwood.com> wrote:
> I can't speak for James, but WireBox (part of the ColdBox family) has been waiting on this functionality to have mixin support for ioc provider methods in Railo.
>
>
>
> For instance, let's say I am concerned about widening the scope of an injected dependency, so instead I create a provider method will retrieve the dependency from the ioc container when I need it at run time.
>
> Let's say the name of the provided object is UserService.  WireBox lets you do that with the following code:
>
>
>
> component name="handler"singleton{
>
>     functiongetUserService() provider="user"{}
>
> }
>
>
>
> The way WireBox achieves this is to replace the getUserService method with a generic provider mixin keeping the original name.  That generic method then usesgetFunctionCalledName() when it is called to know what object it needs to retrieve when you call it.  The only other way around that would be to write a temporary CFM file at run time with the object name baked-in and then cfinclude it at run-time.

br...@bradwood.com

unread,
Feb 9, 2012, 3:49:32 PM2/9/12
to ra...@googlegroups.com
I don't think that would work though since all the injected provider methods would simply be references to a single instance of that function. (unless it was somehow duplicated)  Modifying metadata on one would affect them all.

i.e. 
myObject.foo = myOtherObject.randomMethod;
myObject.bar = myOtherObject.randomMethod;

foo and bar are just named pointers to a single instance of randomMethod.  My assumption is that modifying the metadata of foo would also affect bar and randomMethod as well.

Michael Offner

unread,
Feb 10, 2012, 2:16:58 AM2/10/12
to ra...@googlegroups.com
Exactly! Nothing to add here.
The only way to solve this, is to log every function call, but this slows town the overall execution time of every application, I'm afraid. 

/micha

Vo mim iPad gschickt

br...@bradwood.com

unread,
Feb 10, 2012, 11:21:03 AM2/10/12
to ra...@googlegroups.com
I can appreciate the performance implications, but it is an ACF compatibility issue and a feature that the ColdBox framework relies on for some of our functionality, so it would be great if we could at least give it a shot in Railo.

Alternatively, can you offer any other workarounds to call myObject.foo() which is really executing the myOtherObject.randomMethod function, but somehow be able to tell that "foo" is the thing being called?

Michael Offner

unread,
Feb 14, 2012, 8:36:56 AM2/14/12
to ra...@googlegroups.com
We will do a test release for you. So you can test. 

/micha

Vo mim iPhone gschickt

br...@bradwood.com

unread,
Feb 14, 2012, 6:07:02 PM2/14/12
to ra...@googlegroups.com
Thank you.

~Brad

Sent from my HTC on the Now Network from Sprint!

Brad Wood

unread,
Jul 22, 2012, 3:44:41 PM7/22/12
to ra...@googlegroups.com
Hi Micha,  I was looking through old posts yesterday when I saw this thread I had forgotten about.  What ever became of  RAILO-1670?
The ticket says partially complete.  Did we ever get it working for methods that are mixed into another class at runtime?  To review, this was for frameworks (such as ColdBox) that need to mixin  functionality into user classes where the name of the mixed method is the key to controlling the behavior of the mixin.

Thanks!

~Brad

Michael Offner

unread,
Jul 23, 2012, 3:35:35 AM7/23/12
to ra...@googlegroups.com
this is still on our todo list with the beta, it is not so easy to solve without affecting the overall execution time.
/micha

2012/7/22 Brad Wood <br...@bradwood.com>



--
/micha

Michael Offner CTO Railo Technologies GmbH
Reply all
Reply to author
Forward
0 new messages