Subscribe via Feed

Working out the API for Xsp Classes in XPages

Matt White, Nov 9, 2009 8:30:20 AM

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();


Vince Schuurman, Nov 9, 2009 5:07:22 PM

There is even a proper command for that :)

var obj = getComponent("XSPID");
_dump(obj);



Wesley Guisso, Nov 9, 2009 2:40:22 PM

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



John Mackey, Nov 9, 2009 12:39:21 PM

Nice technique Matt! Thanks for sharing it....

-John



Tim Tripcony, Nov 9, 2009 12:35:21 PM

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.



Frank van der Linden, Nov 9, 2009 12:09:20 PM

cool tip, that's what you call Try and Error




Post a new Comment

Name:


Comment: