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

Calling static methods

Explorer ,
May 29, 2007 May 29, 2007
Hi,
I have a problem with calling static methods after creating a object:
I am using coldfusion 7.0 and this is my code:
When I am using either <cfobject> or createObject the same

<cfobject action="create" type="java" class="com.endeca.navigation.ENEQueryToolkit" name="new_N">
<cfset new_N = createObject("java", "com.endeca.navigation.ENEQueryToolkit")>
<cfdump var = "#new_N#">
<cfset new_N = new_N.selectRefinement(#my_nav_results#, toString(sample_refinement_value))>

1. CFDUMP tells me that object [unknown type] and [unable to convert to string]
2. When I call a static method new_N.selectRefinement(...) i get "The selected method selectRefinement was not found."
3. Arguments to selectRefinement() method are of correct datatype

Below are all methods of this class (all are static):
static boolean isImplicitRefinement(Dimension dim, DimVal refinement)
static DimValIdList removeDescriptor(Navigation n, DimVal descriptor)
static DimValIdList selectAncestor(Navigation n, DimVal ancestor, DimVal descriptor)
static DimValIdList selectRefinement(Navigation n, DimVal refinement)

Any suggestions?
Thank You
TOPICS
Advanced techniques
1.0K
Translate
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

correct answers 1 Correct answer

Explorer , May 30, 2007 May 30, 2007
After reading http://www.bennadel.com/index.cfm?dax=blog:737.view and all related articles i found a solution to the problem: Below is a code that works. First <cfdump> does not give any meaningful results but second <cfdump> after calling static method returns correct value. The problem was with second parameter instead #sample_refinement_value# i had toSring(sample_refinement_value) which caused the error :
Thank you all for the input and suggestions.
<cfset new_N = createObject("java", "com....
Translate
Advocate ,
May 29, 2007 May 29, 2007
First, you don't have to use both createObject() and <cfobject> - one or the other will suffice (personally, I prefer CreateObject()).

Second, are you sure you have set up the java files correctly in your CF administrator / classpath? If you have the following code should show you SOMETHING:

<cfset new_N = createObject("java", "com.endeca.navigation.ENEQueryToolkit")>
<cfdump var="#new_N#">

Until you can get the above code working, your object is not loaded correctly in CF.
Translate
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 ,
May 29, 2007 May 29, 2007
I have been using createOject() and my .jar files are in C:\CFusionMX7\lib . I assume that is correct because I successfully created objects and called non-static methods on them. Schould <cfdump> print all methods that are assosiated with this class even though all methods are static? My cfdump output is clickable box with object [unknown type].

Translate
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 ,
May 29, 2007 May 29, 2007
I agree with insuractive. You need to resolve the createObject() problem first.

>static DimValIdList selectRefinement(Navigation n, DimVal refinement)
Then make sure you're passing in the correct object types. Is #my_nav_results# an instance of "Navigation" and #sample_refinement_value# an instance of "DimVal"? In any case I don't think you need the toString(..) call.

Translate
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 ,
May 29, 2007 May 29, 2007
Yes, placing the jar in C:\CFusionMX7\lib an rebooting is fine.

If the object is valid, Cfdump should print all of its public methods. I don't know if it prints protected or private methods. I thought the cfdump box was expanded by default.. but if you click the box does it show the method names?
Translate
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 ,
May 29, 2007 May 29, 2007
There are only static methods in this class. My first post lists ALL methods this class contains, there aren't any public or private methods.
I am passing correct object types, first argument is of type Navigation and second of DimVal
Translate
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 ,
May 29, 2007 May 29, 2007
When I click on the <cfdump> box instead of methods i see [unable to convert to string] on top section of cfdump box I see object [unknown type]. I have read on lifedocs that in order to call static methods i just have to instantiate object and then call static methods. For other methods (public, or private) I have to use init() to initialize the object. I have tested with and without initialization and it was unsuccessful.
Translate
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
LEGEND ,
May 30, 2007 May 30, 2007
This might help:

http://www.bennadel.com/index.cfm?dax=blog:737.view

If not the article itself, then the links within in.

--
Adam
Translate
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 ,
May 30, 2007 May 30, 2007
After reading http://www.bennadel.com/index.cfm?dax=blog:737.view and all related articles i found a solution to the problem: Below is a code that works. First <cfdump> does not give any meaningful results but second <cfdump> after calling static method returns correct value. The problem was with second parameter instead #sample_refinement_value# i had toSring(sample_refinement_value) which caused the error :
Thank you all for the input and suggestions.
<cfset new_N = createObject("java", "com.endeca.navigation.ENEQueryToolkit")>
<cfdump var = "#new_N#">
<cfset new_N = new_N.selectRefinement(#my_nav_results#, #sample_refinement_value#)>
<cfdump var = "#new_N#">
Translate
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 ,
May 30, 2007 May 30, 2007
LATEST
I knew you didn't need that toString(..) call 😉 Glad its working for you now.
Translate
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