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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

792 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