Tuesday, December 13, 2011

Get Java class names for variables defined in SSJS in XPages


Every global object or variable in SSJS is an object of a class defined in Java. The help documentation says that facesContext is an object of class com.ibm.xsp.domino.context.DominoFacesContext. But what about facesContext.getExternalContext() and other variables?

Well in Java every class inherits directly or indirectly from its base class java.lang.Object. This class has a method named getClass() which returns object of class java.lang.Class (Yes, there is a class called "Class" in Java!). With this you can find out to which class the object belongs, its methods, super class and lot more.

Create a new XPage and add a computed field. Add the code given below for its value and preview it in browser.
Don't forget to set the "Content type" property for computed field to "HTML".


The output should be something like this:


Notice "confusedVar", despite assigning an integer it still is a Double. To make it Integer it has to be initialized with Integer's constructor.

No comments:

Post a Comment