« Back to home

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. There was just one problem: although requestScope ended up with the right keys, the values stored for all the keys were null.

To cut a long story short, the problem was this: Somewhere on my page, I had a custom control which had the createForm attribute set on its xp:view element.

This apparently caused the XPages runtime to create a new form context, which somehow wiped all the data from the request scope.

So: If you find your scoped variable fields mysteriously null—and I see other postings from people who’ve encountered the problem—check all your custom components to see if any of them are creating a form by mistake.