0
Casting Cf struct in Hashtable Java
Explorer
,
/t5/coldfusion-discussions/casting-cf-struct-in-hashtable-java/td-p/579673
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.
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Advocate
,
/t5/coldfusion-discussions/casting-cf-struct-in-hashtable-java/m-p/579674#M53398
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>
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
ik1hsr
AUTHOR
Explorer
,
/t5/coldfusion-discussions/casting-cf-struct-in-hashtable-java/m-p/579675#M53399
Jun 06, 2007
Jun 06, 2007
Copy link to clipboard
Copied
Thanks for the help
now all it works
bye
now all it works
bye
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guide
,
/t5/coldfusion-discussions/casting-cf-struct-in-hashtable-java/m-p/579676#M53400
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>
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>
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

/t5/coldfusion-discussions/casting-cf-struct-in-hashtable-java/m-p/579677#M53401
Apr 03, 2012
Apr 03, 2012
Copy link to clipboard
Copied
cf_dev2, Thanks for that! Picky syntax was holding me up 'till I found your specific example, so thanks!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

