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

Calling static methods

Explorer ,
May 29, 2007 May 29, 2007

Copy link to clipboard

Copied

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

Views

758

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

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....

Votes

Translate

Translate
Advocate ,
May 29, 2007 May 29, 2007

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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].

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

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?

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

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.

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

Copy link to clipboard

Copied

This might help:

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

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

--
Adam

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

Copy link to clipboard

Copied

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#">

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

Copy link to clipboard

Copied

LATEST
I knew you didn't need that toString(..) call 😉 Glad its working for you now.

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