I am trying to invoke a component using the new keyword but it is not working.
The following method below works fine:
<cfset test = CreateObject("component", "test-objects.shipping_new").init(bar="Blah", foo="boom")>
But when I try to use the following:
<cfset test = New test-objects.shipping_new(bar="Blah", foo="boom") />
I get the error tag cfset is not closed. The code above is the first line in the file I am trying to invoke it from, unless I am missing something the tag looks closed to me. I am using Lucee 4.5 if that makes a difference.
The problem is the hyphen:
If the folder name or CFC name has hyphen, use the following syntax:
cfObject=new "cfc-path"(constructorParam1,...)
Related
A simple example of what I'm trying to accomplish using tag based code:
<cfmail
to="someone#x.com"
from="someone#y.com"
subject="howdy"
type="html">
<cfinclude template="path/to/emailtemplates/sometemplate.htm"/>
</cfmail>
I've tried all manner of solutions using cfscript and am at a roadblock. I thought this might do it, but alas no.
savecontent variable="mailBody" {
include "path/to/emailtemplates/sometemplate.htm";
};
mail = new mail();
mail.setTo( "someone#x.com" );
mail.setFrom( "someone#y.com" );
mail.setSubject( "howdy!" );
mail.setType( "HTML" );
mail.setBody( mailBody );
mail.send();
We're not sending multi-part e-mails - just HTML. Is there a way to do this in script?
The issue is that, in cfinlcude you will not be able to include an HTML file. Looks like you are going to need the help of FileRead() function instead of include.
mailBody=FileRead('absolute/path/to/emailtemplates/sometemplate.htm' [, charsetIfNeeded]);
For FileRead to work you should provide an absolute path to an on-disk or in-memory text file on the server.
Not sure if this answers the initial question but fyi in coldfusion 10 I used to be able to tell CF to process other files than cfm. In your application use this line:
<cfset THIS.compileextforinclude = "htm" />
Using facebook4j and to post a link you must create and supply a URL object. However when I try to do so I get a class not found error. Appears CF10 is running on JRE 7.0.15
For example this throws an error
<cfset testurl = createObject("java", "java.lang.URL").init("http://www.google.com") />
but this doesn't for a string object
<cfset testurl = createObject("java", "java.lang.String").init("http://www.google.com") />
Any suggestions would be appreciated.
Right after posting of course I find some old documentation mentioning the class name is java.net.URL
I saw this code example in a recording and wanted to know what the colon syntax did. I searched the docs, but I wasn't able to find any info on it:
weather.subscribe(observer: application.observers.currentConditions);
I know we can use colon in CF9 for ternary operators:
result = (condition) ? true : false;
But in this case it looks like it's being used to provide named arguments; so what's it doing there?
<cfset result = obj.func(arg:value,thing:42) /> I looked at this and
went blink, blink... That can't be right! You can't use colons for
named arguments! Er, can you? Well, apparently you can.
http://corfield.org/blog/post.cfm/Learn_something_new_every_day_named_arguments
Yes, you are allowed to use both. I think it's a matter of preference. You can even mix.
Try this and see, mocked up some test function:
<cffunction name="testFunction" returntype="void" hint="I just spit out the arguments I get">
<cfdump var="#arguments#" label="arguments">
</cffunction>
<cfset testFunction(arg1:"hello",arg2:"world") />
<cfset testFunction(arg1="hello",arg2="world") />
<cfset testFunction(arg1:"I can mix",arg2="my named argument syntax") />
Personally, I prefer = for named arguments. You might also notice that if you use IntelliJ IDEA for your ColdFusion development that they do not recognize the colon syntax, so for better parsing you would want to use the = syntax. I can't speak for other IDEs
Looks like a typo to me. In ColdFusion you would use an equals sign (=) not a colon to used named arguments.
Your example would become:
weather.subscribe(observer = application.observers.currentConditions);
This question already has answers here:
coldfusion weird extra space
(3 answers)
Closed 8 years ago.
I have a CFC that returns a string containing part of a URL. I want to concatenate this to the end of the domain name of the site so it makes a fully qualified URL.
However, the ColdFusion is creating a space before the concatenation. Here is how my concatenation looks:
http://www.mywebsite.com#APPLICATION.MyCFC.GetURL(urlid = url.id)#
So we have two parts:
The domain part which is just http://www.mywebsite.com
The string that's returned from the CFC which is like this /products/20
However the final output ends up like this:
http://www.mywebsite.com /products/20
So for some reason it puts a space just before concatenating the string from the CFC. I have tried to put a Trim() around the CFC invokation but it doesn't do anything.
What I have also tried to do is put the string from the CFC in a variable like this <cfset myurl = #APPLICATION.MyCFC.GetURL(urlid = url.id)#. I then concatenated this variable to the domain like this: http://www.mywebsite.com/#url# and it works fine without adding any spaces.
Why is it doing this? I don't want to keep storing the output of the CFC in yet another local variable everytime I want to use it.
This is the code from the CFC (I've left out the database stuff that it does for sake of confidentially and clarity but its essentially just this):
<cffunction name="GetURL" access="public" returntype="string">
<cfargument name="urlid" required="yes">
<cfset var result="/products/#urlid#">
<cfreturn result>
</cffunction>
add output="false" to your <cffunction> (and <cfcomponent> if it is not an UDF) may solve your problem.
I have the line:
<cfif isArray( this.filters[this.name] )
AND this.filters[this.name].Contains(JavaCast("string",par.fval)) >
which is generating an 'Invalid CFML Construct: contains' error message.
Am I missing something or are the java methods not available when an array is created?
For me the error is a little more explicit:
Invalid CFML construct found on line 1 at column 71.
ColdFusion was looking at the following text:
Contains
And it's saying that because contains is a reserved-ish word in CFML, and something about the combo of that and the square brackets is fooling the parser into thinking there's a problem.
However this sort of thing should work:
<cfset proxy = this.filters[this.name]>
<cfif isArray( this.filters[this.name] ) AND proxy.Contains(JavaCast("string",par.fval)) >
</cfif>
NB: this is a vagary of ColdFusion... Railo does not have this problem. I'm gonna blog it & cross-reference here.