finding and implementing path in cf for cfcomponent

Posted on 2013-01-19
Last Modified: 2013-06-17
I am having difficulty implementing some code that is supposed to find/create the path to a component for my application.

 - The cfcomponent is in the root directory.
 - the file that is calling it is in a directory called 'modules'

the code that is calling it is:
<!--- begin example code --->
<cfset paginationPath = reReplace(replace(getDirectoryFromPath(cgi.script_name), "/", ".", "ALL"), "(^\.|\.modules\.?$)", "", "ALL") />

<cfset       pagination = createObject("component", "#paginationPath#.Pagination").init() />
<!--- end example code --->

it generates the following error:
<!--- begin error example --->
   The name .Pagination is not a valid component name.
Component names cannot start or end with dots.
The error occurred in E:\CustomerData\webspaces\webspace_00104265\wwwroot\modules\E_WebUsers.cfm: line 132

130 :
131 : <cfoutput>
132 : <cfset       pagination = createObject("component", "#paginationPath#.Pagination").init() />
133 : </cfoutput>
134 :


    Check the ColdFusion documentation to verify that you are using the correct syntax.
    Search the Knowledge Base to find a solution to your problem.

Browser         ColdFusion
Remote Address
Date/Time         19-Jan-13 04:51 PM
Stack Trace
at cfE_WebUsers2ecfm1033662156._factor7(E:\CustomerData\webspaces\webspace_00104265\wwwroot\modules\E_WebUsers.cfm:132) at cfE_WebUsers2ecfm1033662156.runPage(E:\CustomerData\webspaces\webspace_00104265\wwwroot\modules\E_WebUsers.cfm:1)

coldfusion.runtime.TemplateProxyFactory$InvalidComponentNameException: The name .Pagination is not a valid component name.
      at coldfusion.runtime.TemplateProxyFactory.resolveName(
      at coldfusion.runtime.CFPage.createObject(
      at coldfusion.runtime.CFPage.CreateObject(
      at coldfusion.runtime.CFPage.CreateObject(
      at cfE_WebUsers2ecfm1033662156._factor7(E:\CustomerData\webspaces\webspace_00104265\wwwroot\modules\E_WebUsers.cfm:132)
      at cfE_WebUsers2ecfm1033662156.runPage(E:\CustomerData\webspaces\webspace_00104265\wwwroot\modules\E_WebUsers.cfm:1)
      at coldfusion.runtime.CfJspPage.invoke(
      at coldfusion.tagext.lang.IncludeTag.doStartTag(
      at coldfusion.filter.CfincludeFilter.invoke(
      at coldfusion.filter.ApplicationFilter.invoke(
      at coldfusion.filter.RequestMonitorFilter.invoke(
      at coldfusion.filter.PathFilter.invoke(
      at coldfusion.filter.ExceptionFilter.invoke(
      at coldfusion.filter.BrowserDebugFilter.invoke(
      at coldfusion.filter.ClientScopePersistenceFilter.invoke(
      at coldfusion.filter.BrowserFilter.invoke(
      at coldfusion.filter.GlobalsFilter.invoke(
      at coldfusion.filter.DatasourceFilter.invoke(
      at coldfusion.filter.RequestThrottleFilter.invoke(
      at coldfusion.CfmServlet.service(
      at coldfusion.bootstrap.BootstrapServlet.service(
      at jrun.servlet.ServletInvoker.invoke(
      at jrun.servlet.JRunInvokerChain.invokeNext(
      at jrun.servlet.JRunRequestDispatcher.invoke(
      at jrun.servlet.ServletEngineService.dispatch(
      at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(
      at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(

<!--- end error example>

This code worked fine, in a previous example. I only changed the directory (as it was given in the example, by the developer) from 'examples' to 'modules' - but apparently, I have missed something else?

thanks for  you help
Question by:btintermedia
LVL 52

Accepted Solution

_agx_ earned 500 total points
ID: 38797540
> The name .Pagination is not a valid component name.

Well that means reReplace is returning an empty string for some reason.  

Sorry I can't answer your question, since it's really about a regular expressions (not CF). You you may want to add the regex topic to the tags to attract attention from the right experts. Since they may not know CF, I'd suggest outputting all of the paths/variables involved. It'll help you (and them) troubleshoot the problem:

<!--- get the result --->
<cfset paginationPath = reReplace(replace(getDirectoryFromPath(cgi.script_name), "/", ".", "ALL"), "(^\.|\.modules\.?$)", "", "ALL") />

<!--- display all variables --->
cgi.script_name = #cgi.script_name#<br>
getDirectoryFromPath(cgi.script_name) = #getDirectoryFromPath(cgi.script_name)#
##paginationPath##.Pagination = "#paginationPath#.Pagination#"<br>

Open in new window

Best of luck!

Expert Comment

ID: 38802680
<cfset pagination = createObject("component", "#paginationPath#.Pagination").init() />

Open in new window

should be
<cfset       pagination = createObject("component", "#paginationPath#Pagination").init() />

Open in new window

On a side note you could also do
<cfset paginationPath = expandPath('./')>

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question