xpages

Human Readable Dates in XPages

Last year Jake published a really good article (as he generally does) about how to create Ruby style dates in LotusScript. So for example, instead of displaying “28/06/2009 09:35” the page will show “about 30 minutes ago”.

It’s a technique I bookmarked until I had a need for it, which I now have, but for an XPages app. So I have ported Jakes code across to use Server Side Javascript instead of LotusScript, and in “share and share alike” fashion, thought I should republish it for you to use as you see fit.

So you can download the code here: xpDates.jss 

Please let me know if you spot any bugs.

An interesting side note is, that if you compare Jakes LotusScript and my server side Javascript, you can see just how easy it is to port code from one syntax to the other. So if you’re just starting out in XPages development and are worried about losing all of your existing LotusScript agents, there really is no need to. You can spend (an admittedly boring) few hours reformatting and not lose any of your existing code at all.

It may not suit all cases, but for the majority of code it’s easier than starting from scratch.

How to add non breaking spaces to your XPages

Often when you’re designing a web page, you’ll need a space between elements (such as two field labels for example). Most of the time you should solve your UI issues with CSS, but sometimes that is not the correct answer. Enter   this is a the classic non breaking space that you can use in HTML.

Unfortunately you cannot use that in your XPages source because it is not valid XML, so instead, we just have to use:

 

160 is the decimal character code for the non breaking space and use of character code markup like this is valid in XML.

A very simple tip, but a useful one none the less.

Running XPages 8.5.0 in IE8

The first thing you’ll notice when you try and open an XPages website in IE8 is a Javascript error. The version of Dojo that ships with 8.5.0 is 1.1.1, this does not support IE8. Hopefully in 8.5.1 Dojo 1.3 will ship so this is a very short term fix.

The aim is for us to set a meta tag in our HTML to tell IE8 to run in IE7 compatability mode. Unfortunately, the built in way of setting meta tags in Domino Designer does not work properly yet so we have to manually add our own tag to the servlet response that the Domino server generates for us.

So if you put the following code into the “beforeRenderResponse” event of your XPage then you should find your site will work properly now.

try {
  if (context.getUserAgent().isIE(8, 8)) {
   var exCon = facesContext.getExternalContext();
       var response = exCon.getResponse();
       response.setHeader(“X-UA-Compatible”, “IE=EmulateIE7”);
    }
} catch (e) {
}

Kudos to Michael Gollmick for this solution.