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".
var stringVar = "string";
var booleanVar = true;
var doubleVar = 1;
var confusedVar:java.lang.Integer = 1;
var integerVar:java.lang.Integer = new java.lang.Integer(1);
return "facesContext.getClass().getName() = " + facesContext.getClass().getName() + "<br>" +
"facesContext.getExternalContext().getClass().getName() = " + facesContext.getExternalContext().getClass().getName() + "<br>" +
"facesContext.getExternalContext().getRequest().getClass().getName() = " + facesContext.getExternalContext().getRequest().getClass().getName() + "<br>" +
"facesContext.getExternalContext().getResponse().getClass().getName() = " + facesContext.getExternalContext().getResponse().getClass().getName() + "<br>" +
"stringVar.getClass().getName() = " + stringVar.getClass().getName() + "<br>" +
"booleanVar.getClass().getName() = " + booleanVar.getClass().getName() + "<br>" +
"booleanVar.getClass().getName() = " + doubleVar.getClass().getName() + "<br>" +
"confusedVar.getClass().getName() = " + confusedVar.getClass().getName() + "<br>" +
"integerVar.getClass().getName() = " + integerVar.getClass().getName();
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