• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to instantiate a component inside a directory containing a dot (.) character without a mapping?

Guest
May 17, 2017 May 17, 2017

Copy link to clipboard

Copied

Path to the CFC I'm trying to instantiate is:

/webroot/client/com.client.www/model/SomeComponent

where "/webroot" is a ColdFusion mapping to the actual web root. I'm trying to make this work *without* having to create a mapping.

I'm using CreateObject(). I can't use the dot-notation format (webroot.client.com.cllient.www.model.SomeComponent) because the directory name "com.client.www" would be interpreted as 3 levels deep which is wrong, it's one directory name. So, I'm using the path instead. However a path with a directory with a dot in the name appears to confuse ColdFusion. For example, this works:

CreateObject("component", "/webroot/client/website/model/SomeComponent")

but this does not:

CreateObject("component", "/webroot/client/com.client.www/model/SomeComponent")

Clearly the dots are causing some trouble. The reverse domain name format I've got here is a silly old thing that we're migrating away from, but in the mean time old projects have this format so we've got to deal with it.

I've done a lot of Googling and can't find anything other than a lone blog page from 7 years ago saying that you've got to create a CF mapping. Surely there is another way! Thanks for any help you can provide!

EDIT: Running ColdFusion Server 9,0,2,282541 on Ubuntu.

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , May 18, 2017 May 18, 2017

Why can you not create a mapping? Even if its just for this request?

There probably isn't going to be another way as it just easier to create the mapping.

Votes

Translate

Translate
Advocate ,
May 18, 2017 May 18, 2017

Copy link to clipboard

Copied

Why can you not create a mapping? Even if its just for this request?

There probably isn't going to be another way as it just easier to create the mapping.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 18, 2017 May 18, 2017

Copy link to clipboard

Copied

I have to concur with haxtbh​ on this.  Creating a mapping in CFAdmin or within the application.cfc shouldn't be an issue.

However, I have a thought.  I have not tested this, so I'm not sure if this will work, for you, or not.

Replace the '.' of the folder name with chr(046).

CreateObject("component","/webroot/client/com#chr(046)#client#chr(046)#www/model/SomeComponent");

HTH,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2017 May 18, 2017

Copy link to clipboard

Copied

The dot is a special character in ColdFusion and in the underlying Java engine. Perhaps in Linux, too. You may get away with it this time. But you will, sooner or later, encounter issues difficult to debug.

The solution is to change the directory name. For example, replace the dot by the underscore _. Then review the rest of your software and make the necessary changes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

I was wanting to avoid making a mapping because it's simpler to not have to make a mapping. Because of the way our projects are structured, there will be one mapping per project with a dot-notation directory name in the path. I'm not arguing that making a mapping is a huge complexity boost, it's not, but it does add one more thing to the list of stuff the code has to manage.

It does seem like making a mapping is the way to go. I appreciate the help!

This issue with CreateObject() does have surprising behavior to me; despite the period being a special character in CF / Java, I still expected that would work given it's a valid character to put in a directory name. At the very least I would expect the docs to mention this character. So this isn't a bug per se, more like a documentation shortcoming.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

TL;DR

If your component resides in a directory under your site root or a virtual folder under the site root you can just insert dots where forward slashes would be as if referencing from the client. In other words, http://somedomain.com/cfc/common/component.cfc could be initiated as "cfc.common.component".

Does that help?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

  You shoulda read.

It isn't that.  OP has components in a folder under a folder that has dots as part of the folder name ("com.client.www") and the dots in the folder name are confusing CF Server because it thinks the components are located in /webroot/com/client/www/components instead of /webroot/com.client.www/components.

V/r,

^_^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
May 19, 2017 May 19, 2017

Copy link to clipboard

Copied

LATEST

Ah... Never mind.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation