XPages Tip: Using _dump to write information to the server console

I recently showed how to use a built-in client-side JavaScript function to dump the contents of an object for review. In this post, I’ll show a somewhat similar method available in Server-Side JavaScript.

_dump() is a global method available in SSJS. You can use it to write the contents of an object out to the server console (and log).

The XPages Portable Command Guide mentions using it to dump the contents of scope variable maps.

Since the requestScope automatically has a bunch of properties, I can see the results if I run this beforePageLoad:

_dump(requestScope);

Here is the output on the server console — basic URL, user, server, and page info:


HTTP JVM: com.sun.faces.context.RequestMap
HTTP JVM: =
HTTP JVM: {database=BlogTesting.nsf, __xspconvid=null, opensession=CN=XDev9/O=Xcellerant, userScope={}, session=CN=XDev9/O=Xcellerant, cookie={SessionID=javax.servlet.http.Cookie@7190719}, component
HTTP JVM: arameters=com.ibm.xsp.application.ComponentParameters@3f953f95, context=com.ibm.xsp.designer.context.ServletXSPContext@56fc56fc,
identityScope={}, serverScope={Anonymous={}}, opendatabase=BlogTesting.nsf, com.ibm.xsp.SESSION_ID=B7117B555E750057C2668FD5A46
HTTP JVM: 51CB288B7621}

The sessionScope is empty by default, but I can add a few properties and then look at the output:

sessionScope.property1 = 'abc';
sessionScope.property2 = 'def';
_dump(sessionScope);

HTTP JVM: com.sun.faces.context.SessionMap
HTTP JVM: =
HTTP JVM: {__XSP_STATE_FILE=com.ibm.xsp.application.FileStateManager$SessionState@70647064,
__notescontext_publicaccess=com.ibm.domino.xsp.module.nsf.NotesContext$AccessPrivileges@2a0b2a0b, property2=def, xsp.sessionData=com.ibm.xsp.designer.context.PersistentSessi
HTTP JVM: nData@34fb34fb, property1=abc}

Not exactly easy to read, but the information is there.

But you’re not limited to scope variables. Here’s an example of creating my own object and writing it out:

var myObject = {};
myObject.foo = 'xyz';
myObject.bar = 'uvw';
_dump(myObject);

HTTP JVM: Object
HTTP JVM: =
HTTP JVM: [object Object]
HTTP JVM:
HTTP JVM: +-
HTTP JVM: foo
HTTP JVM: :
HTTP JVM: string
HTTP JVM: =
HTTP JVM: xyz
HTTP JVM:
HTTP JVM: +-
HTTP JVM: bar
HTTP JVM: :
HTTP JVM: string
HTTP JVM: =
HTTP JVM: uvw

This seems ridiculously spread out, but it’s pretty easy to see the contents of the object.

All in all, MarkLeusink’s Debug Toolbar is a much nicer tool to use when working with scope variables, but if you’re doing some quick debugging — or setting up a consistent method of handling errors, the _dump() method can come in handy.

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: