Skip to main content
vksrinu
Inspiring
June 18, 2009
Question

Array of Struct values to Java.

  • June 18, 2009
  • 1 reply
  • 2865 views

Hi,

I am looking to send the array of struct values to the Java method. Whats the better way to do it?

For a simple paratmeter i am able to call method. but i am looking to send the array of struct values to java mthod. but its not working as there is such thing in java.

does any have  any solution for this.

This is what i am looking:

<cfset myBook = ArrayNew(2)>

<cfset myBook1 = StructNew()>
<cfset a = StructInsert(myBook1, "title", "Title", 1)>
<cfset a = StructInsert(myBook1, "author", "Author", 1)>
<cfset a = StructInsert(myBook1, "description", "Book Description", 1)>
<cfset a = StructInsert(myBook1, "publishyear", "Publish Year", 1)>
<cfset a = StructInsert(myBook1, "isbn", "ISBN Number", 1)>

<cfset myBook2 = StructNew()>
<cfset a = StructInsert(myBook2, "title", "More ColdFusion", 1)>
<cfset a = StructInsert(myBook2, "author", "David Medlock", 1)>
<cfset a = StructInsert(myBook2, "description", "More ColdFusion Info", 1)>
<cfset a = StructInsert(myBook2, "publishyear", "2005", 1)>
<cfset a = StructInsert(myBook2, "isbn", "321654DCBA", 1)>

<cfset myBookArray = ArrayNew(1)>
<cfset myBookArray[1] = myBook1>
<cfset myBookArray[2] = myBook2>
<cfdump var="#myBookArray#">

<cfobject action = "create" type = "java" class = "SimpleMethod" name = "objSimpleMath">
<cfset retval = objSimpleMath.test(myBookArray )>

I cant able to pass the myBookArray  to the java method test. what kind parameter should it be. ?

Thanks in advance.

Srinivas

This topic has been closed for replies.

1 reply

Inspiring
June 18, 2009

I cant able to pass the myBookArray  to the java method test. what kind parameter should it be. ?

That is determined by your java class. We would have to see the java code and error message to advise you on which types to use.

Some objects can be automatically converted, while others you may need to create explicitly with createObject("java", ...).  Here is a matrix that describes the conversion of ColdFusion objects to java data types.

         http://livedocs.adobe.com/coldfusion/8/htmldocs/Java_8.html

vksrinu
vksrinuAuthor
Inspiring
June 19, 2009

But I am using the CF ver 5.0 and Java 1.3. so i cant have all the adv

features.

Srinivas

Inspiring
June 19, 2009

I am not familiar with CF5, but you should check the documentation about what automatic conversions are possible.  I cannot be more specific without seeing the java code for your class.

http://www.adobe.com/livedocs/coldfusion/5.0/Developing_ColdFusion_Applications/cfobject8.htm