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

Casting Cf struct in Hashtable Java

Explorer ,
May 30, 2007 May 30, 2007

Copy link to clipboard

Copied

Hi;
i need to convert a Coldfusion Struct in a Java Hashtable (as th CFMX manual tell);
I have this java class:


public class Pratica {
private java.util.Hashtable my;
public Pratica(){
my=null;
}
public Pratica(java.util.Hashtable dbprop){
my=dbprop;
}
public void set(java.util.Hashtable dbprop){
my=dbprop;
}

}

and in the CF page i have this code:

<cfset ma = createObject("java","java.util.Hashtable")>
<cfset ma.init(glb)> // glb is a struct

<cfobject action="CREATE" type="JAVA" class="Pratica" name="pra">
<cfset pra.init(ma)>

but when i run...:
"Unable to find a constructor for class Pratica that accepts parameters of type ( java.util.Hashtable )."

I'm waiting your suggestions!!!
thanks to all


Andrea
ps:sorry for my english.
TOPICS
Advanced techniques

Views

1.5K

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 30, 2007 May 30, 2007

Copy link to clipboard

Copied

There does not seem to be a constructur for Hashtable that accepts a CF structure as a parameter. Take a look at the java documentation:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html#Hashtable(int,%20float)

Given, I haven't tried to go from CF struct to hashtable before - could you do something like this?

1) Initialize an empty Hashtable
<cfset myHashTable= createObject("java","java.util.Hashtable")>
<cfset myHashTable.init()>

2) loop over the CF structure collection and call the Hashtable's put() method to populate the hashtable
<cfloop collection="#glb#" item="key">
<cfset myHashTable.put(key, glb[key])>
</cfloop>

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
Explorer ,
Jun 06, 2007 Jun 06, 2007

Copy link to clipboard

Copied

Thanks for the help
now all it works
bye

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
Guide ,
Jun 06, 2007 Jun 06, 2007

Copy link to clipboard

Copied

ik1hsr,

In MX6/7 a ColdFusion Struct is a Hashtable. So you don't need to create a new one. Just pass in the CF Struct object.

Java Class:

public class Pratica {
private java.util.Hashtable my;
public Pratica(){
my=null;
}
public Pratica(java.util.Hashtable dbprop){
my=dbprop;
}
public void set(java.util.Hashtable dbprop){
my=dbprop;
}

public String getKeyValue(Object key) {
if (my != null) {
return my.get(key).toString();
}
return "";
}
}


ColdFusion Code:

<cfset theKey = "abc" />
<cfset cfStruct = structNew()>
<cfset cfStruct[theKey] = "abc" />
<cfset pra = createObject("java", "Pratica").init(cfStruct) />
<cfoutput>#theKey# value = #pra.getKeyValue(theKey)#</cfoutput>

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
Apr 03, 2012 Apr 03, 2012

Copy link to clipboard

Copied

LATEST

cf_dev2, Thanks for that!  Picky syntax was holding me up 'till I found your specific example, so thanks!

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