9 Replies Latest reply on May 30, 2007 3:00 PM by cf_dev2

    Calling static methods

    marekss
      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
        • 1. Re: Calling static methods
          insuractive Level 3
          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.
          • 2. Re: Calling static methods
            cf_dev2 Level 1
            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.

            • 3. Re: Calling static methods
              marekss Level 1
              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].

              • 4. Re: Calling static methods
                cf_dev2 Level 1
                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?
                • 5. Re: Calling static methods
                  marekss Level 1
                  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
                  • 6. Re: Calling static methods
                    marekss Level 1
                    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.
                    • 7. Re: Calling static methods
                      Level 7
                      This might help:

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

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

                      --
                      Adam
                      • 8. Re: Calling static methods
                        marekss Level 1
                        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#">
                        • 9. Re: Calling static methods
                          cf_dev2 Level 1
                          I knew you didn't need that toString(..) call ;-) Glad its working for you now.