0
Problem with Java functions within a CFC
Engaged
,
/t5/coldfusion-discussions/problem-with-java-functions-within-a-cfc/td-p/854144
Nov 30, 2008
Nov 30, 2008
Copy link to clipboard
Copied
Hi,
I looked on CFLIB for a function that would return the current URL. I found a really neat one which doesn't use the sometimes unreliable cgi variables.
It goes something like this:
<cffunction name="getCurrentURL" hint="Gets the current URL" returntype="string" output="false" access="public">
<cfset var currentURL = getPageContext().getRequest().GetRequestUrl().toString() />
<cfif len(trim(cgi.query_string))>
<cfset currentURL = currentURL & "?" & cgi.query_string />
</cfif>
<cfreturn currentURL />
</cffunction>
If I call this on like a top level index.cfm it works perfectly...however, if I put this function into a CFC, I get an odd string returned looking something like:
cfutils2ecfc1871686742$funcGETCURRENTURL@666b79
There's no error, but the string it sends back is clearly very odd.
Is there a way to use this function within a CFC? I figured it made sense as I would be using something like this quite a lot and don't want to repeat myself.
Many thanks,
Mikey.
I looked on CFLIB for a function that would return the current URL. I found a really neat one which doesn't use the sometimes unreliable cgi variables.
It goes something like this:
<cffunction name="getCurrentURL" hint="Gets the current URL" returntype="string" output="false" access="public">
<cfset var currentURL = getPageContext().getRequest().GetRequestUrl().toString() />
<cfif len(trim(cgi.query_string))>
<cfset currentURL = currentURL & "?" & cgi.query_string />
</cfif>
<cfreturn currentURL />
</cffunction>
If I call this on like a top level index.cfm it works perfectly...however, if I put this function into a CFC, I get an odd string returned looking something like:
cfutils2ecfc1871686742$funcGETCURRENTURL@666b79
There's no error, but the string it sends back is clearly very odd.
Is there a way to use this function within a CFC? I figured it made sense as I would be using something like this quite a lot and don't want to repeat myself.
Many thanks,
Mikey.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
LATEST
/t5/coldfusion-discussions/problem-with-java-functions-within-a-cfc/m-p/854145#M78761
Nov 30, 2008
Nov 30, 2008
Copy link to clipboard
Copied
a request to a .cfc is a separate request, and thus has its
own
PageContext, which is not same as PageContext of requesting template...
and what's so unreliable about cgi.script_name???
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
PageContext, which is not same as PageContext of requesting template...
and what's so unreliable about cgi.script_name???
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

