http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=part_dev.htm
Invoking objects
Thecfobjecttag makes Java objects available in ColdFusion MX. It can access any Java class that is available on the JVM classpath or in either of the following locations:
- In a Java archive (.jar) file in web_root/WEB-INF/lib
- In a class (.class) file in web_root/WEB-INF/classes
For example:
<cfobjecttype="Java" class="MyClass" name="myObj">Although the
cfobjecttag loads the class, it does not create an instance object. Only static methods and fields are accessible immediately after the call tocfobject.If you call a public non-static method on the object without first calling the
initmethod, there ColdFusion makes an implicit call to the default constructor.To call an object constructor explicitly, use the special ColdFusion
initmethod with the appropriate arguments after you use thecfobject tag; for example:<cfobjecttype="Java" class="MyClass" name="myObj">
<cfset ret=myObj.init(arg1, arg2)>Note: The
initmethod is not a method of the object, but a ColdFusion identifier that calls thenewfunction on the class constructor. So, if a Java object has aninitmethod, a name conflict exists and you cannot call the object'sinitmethod.To have persistent access to an object, you must use the
initfunction, because it returns a reference to an instance of the object, andcfobjectdoes not.An object created using
cfobjector returned by other objects is implicitly released at the end of the ColdFusion page execution.
Btw - you may want to brush up on your OO vocabulary. I think you meant to say you could 'not find a init method in this class' or something to that effect.
MarkOn 3/21/06, Dale Fraser <[EMAIL PROTECTED]> wrote:
Hey,
I'm no Java guru, but I don't see a constructor class or init method in this
function.
Regards
Dale Fraser
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On
> Behalf Of Mark Mandel
> Sent: Tuesday, 21 March 2006 13:02 PM
> To: [email protected]
> Subject: [cfaussie] Re: Call Java Class (Java Code Attached)
>
> Actually - what just popped into my head -
>
> Try this -
>
> <cfscript>
> myObj = createObject("java", "IceKey").init();
> </cfscript>
>
> I have found on occasion you actually need to explicitly call the default
> constructor on the Java object, otherwise you get weirdness.
>
> I'm not really sure why it is, I have a feeling it may have something to
> do with static attributes - therefore I tend to call init() on all
> constructors by default.
>
> Try that, and see if that works.
>
> Mark
>
>
--
E: [EMAIL PROTECTED]
W: www.compoundtheory.com
ICQ: 3094740
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "cfaussie" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cfaussie
-~----------~----~----~----~------~----~------~--~---
