typeof() – lifesaving debugger tool

OK so maybe life saving is a little stretch but in this article I will illustrate an occurrence of where using type of() helped solve a real world problem.

The Problem

I wanted to display a data source within a repeat control – relatively simple situation I guess but my brain was asleep that particular morning. I wanted to display the repeat control value within a computed text control……seemed simple

	<xp:this.data>
		<xp:dominoView var="viewSortOrder" viewName="vwSortOrder"></xp:dominoView>
	</xp:this.data>
<xp:repeat var="repeatSortOrder" id="repeat1" value="#{viewSortOrder}" disableOutputTag="true">
	<xp:text tagName="li" escape="false" disableTheme="true">
		<xp:this.value><![CDATA[#{javascript:var temp=""
		temp=temp+repeatSortOrder.title //here is the repeat
		.......
	</xp:text>
</xp:repeat>

Unfortunately this created an error 500 – one of the most useless errors known to XPages but I knew something was wrong…but what?

The answer

Then to my rescue comes “Super TroyReimer” who is of course one of the smartest people I know and he says “oo I dunno let’s find out”

“Why don’t we start by finding the typeof for the repeatSortOrder”?

“errrrrr ok *shaking head and humoring MrSmartGuy*”

so I ran a quick print to the screen and look what came back?

println(typeof(repeatSortOrder))

ty1

Oh well DUH Marky……

The repeat control in this context is running a notesViewNavigator in the Java code (I knew that) and therefore in the computed context it is returning a notesview entry every time the repeat cycles….

So in that case the solution is not repeatSortOrder.title is it repeatSortOrder.getColumnValue(‘title’)

	<xp:this.data>
		<xp:dominoView var="viewSortOrder" viewName="vwSortOrder"></xp:dominoView>
	</xp:this.data>
<xp:repeat var="repeatSortOrder" id="repeat1" value="#{viewSortOrder}" disableOutputTag="true">
	<xp:text tagName="li" escape="false" disableTheme="true">
		<xp:this.value><![CDATA[#{javascript:var temp=""
		temp=temp+repeatSortOrder.getColumnValue('title') //here is the repeat
		.......
	</xp:text>
</xp:repeat>

and that works just fine

Conclusion

Troy Reimer is a very smart person

We all have brain farts and I hope you are as lucky to work with some really smart people like I am

typeof() is a very smart way of figuring out why your object is not what you think it is in SSJS

7 thoughts on “typeof() – lifesaving debugger tool

  1. Hi,
    good tip – I have also learned the hard way to use typeof during debugging to understand what is going on (and wrong, mostly).
    Just to clarify this a bit: typeof is an *operator*, no function in JavaScript: so “typeof repeatSortOrder” would do the same as “typeof (repeatSortOrder)”.

  2. Agreed it is very handy. I have found in loops that ssjs changes up an undeclared date variable into text due to a bad single data point.

    So I simply declare or cast my variables always just like java.

    If repeatSortOrder was declared it may have been obvious too.

    • Thanks Rami – In this case repeatSortOrder is the variable name of the repeat control which is why it is not declared

      var=”repeatSortOrder”

    • A variable declaration will be ignored from the SSJS runtime. If you do something like this…

      var i:java.lang.Double = facesContext;

      … there is no exception / error thrown. The type of “i” has now changed to the type of the facesContext.

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 )

Facebook photo

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

Connecting to %s