Working out the API for Xsp Classes in XPages
Tuesday, November 10, 2009 at 1:30AM One of the biggest problems I have is interacting with the various components of an XPage programatically. It's not that I can't get hold of them, but it is that I don't know what classes they are from a Java point of view, and therefore don't know what methods and properties I have available to me.
So my solution is to first create an error. Say, for example, I want to programatically control a Pager control. I'll add a button to my XPage with an onClick event something like this:
getComponent("pager1").setStart(1);
I know this will fail, but if I have the default error page enabled then I'll get an error message like this:

And from the error message I can now tell that the object I want to talk to is of the class "com.ibm.xsp.component.xp.XspPager" and when I add that to the variable definition I'll get full type ahead of the API for that class in Domino Designer. So now I know that I can write something like this:
var pager:com.ibm.xsp.component.xp.XspPager = getComponent("pager1");
pager.gotoFirst();

Controls,
api,
documentation in
Tips and Tricks 
Reader Comments (5)
cool tip, that's what you call Try and Error
For what it's worth, the following syntax will also tell you the class of any control:
typeof getComponent("pager1")
So if you want to extract the class name without triggering an error, you can create a computed field and set its value to return the class name of another control via typeof.
Nice technique Matt! Thanks for sharing it....
-John
Other technique:
var file = getComponent("fileUpload1");
print(file);
you get in console the class
10/11/2009 13:36:08 HTTP JVM: com.ibm.xsp.component.xp.XspFileUpload@78c778c7
There is even a proper command for that :)
var obj = getComponent("XSPID");
_dump(obj);