Gaulin, Mark wrote:
> Hi
> I'm looking for a good way to dump the public properties of a java
> object, but it should include values available from getX() methods, not
> just public "field" members (which I don't ever have).
> 
> It could be a java solution or a cf custom tag (of cfc).
> 
> If someone has a head-start on a custom tag that uses java reflection,
> I'll pick that up and run with it.

this was a fun little challenge.  Maybe this will help you.

The following function accepts a java object as an argument, and dumps 
the value of every getXXX() method that requires no arguments.

<cffunction name="dumpJavaObject">
        <cfargument name="obj" type="any" required="yes">
        <cfset var methodname = "">
        <cfset var classInfo = obj.getClass()> <!--- class object --->
        <cfset var methods = classInfo.getMethods()>
        <cfset var I = 0>
        
        <cfloop from="1" to="#ArrayLen(methods)#" step="1" index="I">
                <cfset methodName = methods[i].getName()>
                <cfif refind("^get",methodName) gt 0>
                        <cfif arrayLen(methods[i].getParameterTypes()) is 0>
                                <cfoutput><hr>#methodName# = <br></cfoutput>
                                <cftry>
                                        <cfdump 
var="#evaluate("obj.#methodName#()")#">
                                        <cfcatch type="any">
                                        Unable to dump 
##evaluate("obj.#methodName#()")##<br>
                                        </cfcatch>
                                </cftry>
                        </cfif>
                </cfif>
        </cfloop>
</cffunction>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:231670
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to