« Back to home

Controller-based server-side validation in XPages JavaScript

Think about your last tax return. If you have investment income, a whole additional set of questions has to be answered. If you own overseas investments, that’s another set of fields to fill out. Disposed of any stock? That’ll be more questions. My experience is that most business forms end up like this. They start out simple, but sooner or later someone says “Well, if they answer yes to this question, we’ll need to ask them another question with three possible answers, and depending on their answer they might need to put a project code in another field…” and suddenly you’re off down the dynamic forms rat hole.…

Read more »

JDK 8 JavaScript scripting experiment, with added Domino

Oracle’s new JDK 8.0 includes a new JavaScript engine called Nashorn, designed to support both embedded JavaScript in Java applications, and standalone command-line JavaScript. As well as accessing JavaScript from Java code, you can do the reverse, and access Java classes from JavaScript — just like in IBM Domino XPages. The new scripting features are now a standard part of the JRE. For now, the command to actually run a script is described by Oracle as “experimental and unsupported”, but I wasn’t going to let that put me off; I immediately wondered how easy it would be to write a command-line script which accessed Domino data, using only JavaScript.…

Read more »

Scope variables mysteriously null in XPages

I just spent about a day tracking down the cause of a problem in an XPages application, which turned out to be due to a truly trivial error that produced no warnings or error messages. So, here’s a writeup of the issue… I was building a live search page, with various form components set out for selecting search options. I followed the normal pattern of binding the components to various parameters on requestScope, and then having an event handler which pulled them out, constructed a search string, and passed that to the view.…

Read more »

JavaScript function syntax revisited

A commenter pointed out that my previous posting on function in JavaScript missed out some subtle differences between function as a way to create lambdas which are assigned to variables, and function as a statement which creates a function variable. The function statement actually has one benefit: Functions defined using it are lifted to the top of the context which contains them. This means you can refer to them before you define them.…

Read more »

Fun with vim and var

A common style guideline in JavaScript is to use a single var declaration at the top of your functions. This is because even if you use multiple var declarations scattered throughout the code, JavaScript’s scoping rules mean that the variables are actually defined at the top of the function that contains them — so why not make your code reflect reality? So you end up with functions that look like this:…

Read more »

JavaScript module patterns and code size

A few days ago I did some code refactoring: File Bytes before Bytes after requestform.js 41491 45884 requestform-min.js 23565 21058 What’s going on here? Well, the code is quite old, and was written using the direct assignment method of global abatement. Now that I’m more comfortable with JavaScript, I rewrote the code to use the revealing module pattern.…

Read more »

The whys of Unobtrusive JavaScript

The HTML standards provide attributes on many elements, enabling you to set them up to call JavaScript when an event occurs. For example, a text field might use the onchange attribute to call some JavaScript to trim whitespace from the beginning and end of the value: <input type="text" id="field1" name="username" onchange="trim(‘field1’);"> However, this method of working has gradually become unpopular. Instead, most now seem to recommend setting up all the events on a page using a JavaScript routine; a practice called unobtrusive JavaScript.…

Read more »

JavaScript modulus weirdness

I just became aware of an interesting JavaScript ‘feature’. The code y = x % 1; is equivalent to y = x - Math.floor(x); because ECMA-262 says: … the floating-point remainder r from a dividend n and a divisor d is defined by the mathematical relation r = n − (d * q) where q is an integer that is negative only if n/d is negative and positive only if n/d is positive, and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d.…

Read more »

JavaScript: The Good Parts

I remember back in the 1980s paying something like £40 for a copy of Kernighan and Ritchie’s original book on “The C Programming Language”. An outrageous amount for a book which was a little over 200 pages, I thought. However, during the 1990s, something happened to books about computer programming. Like the fast food junkies of our nations, they started to get bigger and bigger, with the essential meat surrounded by more and more extraneous fat.…

Read more »