JavaScript for XPages: Writing Successful Client-Side Code

Scott Good, President, Teamwork Solutions, Inc.


February, 2010


Working with JavaScript in XPages is not the same as working with JavaScript in classic Notes and Domino, nor anywhere else for that matter. Discover the differences and learn techniques and concepts for writing client-side JavaScript in XPages. This is the first of a series of articles for Domino developers on adapting their JavaScript skills for XPages.


Are you an experienced Domino developer who is new to XPages and XPages development? If you’ve spent any time trying to build XPages applications, you may have already taken a few rides on the XPages roller coaster. At first you’re thrilled. The ease with which you can do things that used to be comparatively hard — particularly for Web development — is a little amazing. But then you start trying to do something easy, something you’ve done successfully for years, and you can’t get it to work. Grrrr.
My early experiences with XPages felt a little like learning to ice skate. I would alternate between gliding effortlessly across the pond and crashing unceremoniously onto my face. It was exhilarating and frustrating at the same time. Surprisingly, with XPages a lot of the frustration came from JavaScript.
JavaScript? How could that be? I’ve been writing JavaScript code for nearly a decade, developing sophisticated JavaScript-based user interfaces for clients around the world and writing extensively on using JavaScript in the Domino environment. JavaScript is what I do. And yet, there I was, staring at my monitor in confusion as I failed to be able to do something as simple as retrieve the value of a text field with my code. How can that not work? I asked myself on more than one occasion, ready to throw in the towel.
The truth is, XPages presents us Domino developers with a new playing field. There are amazing new capabilities — such as access to multiple data sources, effortless Ajax, and write-once-use-everywhere capabilities between browser and client — but to make use of them we have to learn to do things differently, especially where JavaScript is concerned. For instance, in addition to the usual client-side browser-based JavaScript code, in XPages there is server-side JavaScript, an extremely powerful capability which includes a whole new object model (much of it based on LotusScript) and a multitude of @Functions (based on the @Formulas that have been in the Notes client since the earliest releases). For the ultimate in flexibility, you can also access server-side JavaScript from client-side code ...sometimes.
And that’s the rub. What can happen surprisingly quickly is all these new capabilities, combined with a new user interface in Domino Designer, become confusing to the point where you may find yourself wanting to give up in frustration. But do yourself a favor and continue. You see, JavaScript is not so much harder to write in XPages as it is different. You have to think about certain parts of it differently than you do in other environments, even when you’re trying to do seemingly simple things that shouldn’t require a lot of thinking. Whether you’re already working in XPages and have experienced some of the same frustration I’ve described, or you’re new to JavaScript in XPages, I’ll show you the techniques and concepts you need to get started down the right road, with a minimum of confusion and frustration.

Would you like to see the full version of this article?

If you are an electronic license holder to THE VIEW, please log in to view this article.

If you would like information about becoming an electronic license holder — and having 24/7 unrestricted access to all articles and content in THE VIEW Online Knowledgebase — click here to see the available subscription options.

Or call 1-781-751-8813 to speak directly with a subscription and licensing specialist about customized access for you and your team.