Geoff,

You can't create a java array directly from CF, at least I have not been able to find a way.  Instead, you need to use reflection to create the array:

// Create an Array
someArray      = createobject("java", "java.lang.reflect.Array");

// Create the type of Object your Array is going to contain
someObjectType = createObject("java", "com.somepackage.SomeObjectType").init();

// Create an array and specify the type of object you are creating, and the number of elements you expect it to hold
actualArray = someArray.newInstance(someObjectType.getClass(), 3);

Then you can populate it as normal:

// Create the object
someObjectInstance = createObject("java", "com.somepackage.SomeObjectType").init();

// Set its attributes/member variables
someObjectInstance.setAttribute1("blah");
someObjectInstance.setAttribute2("blah2");
someObjectInstance.setAttribute3("blah3");

// set the "0" element of the array to the object that you just created
someArray.set( actualArray, 0, someObjectInstance );

Repeat the populatuion steps for each element of the array.

I hope that helps.

Thanks,

Jim M.



----- Original Message ----
From: Geoff Parkhurst <[EMAIL PROTECTED]>
To: [email protected]
Sent: Friday, September 8, 2006 4:16:58 AM
Subject: [CFCDEV] Create java object in an array

I'm trying to convert a PayPal .JSP express checkout example into a
ColdFusion CFC, but am having difficulties with an array of java objects.

Here's the relevant bit of the jsp:

PaymentDetailsItemType[] paymentItems = new PaymentDetailsItemType[3];
PaymentDetailsItemType paymentItem = new PaymentDetailsItemType();
paymentItem.setName("Photographic Print - Tropical Sunset");
Etc...

Previously, all these java bits are created fine. E.g.:

pp_request=CreateObject("java","com.paypal.soap.api.DoExpressCheckoutPayment
RequestType");

But I can't see how to do the same CreateObject syntax for an array.

Any help would be much appreciated.

Many thanks,
Geoff




You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]



You are subscribed to cfcdev. To unsubscribe, please follow the instructions at http://www.cfczone.org/listserv.cfm

CFCDev is supported by:
Katapult Media, Inc.
We are cool code geeks looking for fun projects to rock!
www.katapultmedia.com

An archive of the CFCDev list is available at www.mail-archive.com/[email protected]

Reply via email to