Quick Search
Social Sites
Lotus Community


Thursday
Sep022010

A small tip for upgrading your XPages apps from 8.5.1 to 8.5.2

If you have been using Stephan Wissel's "Web Agents, XPages Style" technique for outputting non-HTML content from your XPages, you may run into a problem when you upgrade your server to 8.5.2.

In the original afterRenderResponse sample code, you would use something like...

try{
    var exCon = facesContext.getExternalContext(); 
    var writer = facesContext.getResponseWriter();
    var response = exCon.getResponse();
    response.setContentType("text/plain");
    writer.write("Hello World");
    writer.close();
}catch(e){
    _dump(e);
}

What you may find is running that code on your lovely new 8.5.2 server will result in an Error 500 with no detail of the error itself. To fix the problem, simple remove the

writer.close();

line from the source code and you should be good to go.

Wednesday
Aug252010

What's new with XPages in 8.5.2

Over on XPages101.net I've just posted (yet another) video. This time we're looking at what's new in 8.5.2 for the XPages developer.

What's New With XPages in 8.5.2

As a bit of a teaser, I thought I'd post the audio from that recording here as well so that you can hear what you're missing. As ever, feel free to subscribe if you want to get a jumpstart on your XPages development. There are 30 different videos up on the site covering all the elements you'll need to get started and then dig a little deeper into XPages development. The full video listing can be found here.

Friday
Aug062010

Heading home

It seems like a long time since I went away on holiday, and it is. Since the middle of July I've been to Latitude (great), Madeira (great), IamLUG (great) and run an XPages101 day (seemed to go well). So all in all it's been a really enjoyable few weeks.

I'm sat in JFK airport in New York waiting to start the final leg of the journey home and much as it's been a great couple of weeks away, I am *really* looking forward to getting back home and just decompressing for a couple of days before getting back into the real world with a vengeance on Monday morning.

IamLUG was a really superb event, Chris and the rest of the team do put on a good show. Everything was run incredibly smoothly, the content was very good indeed and, as ever, the people were great company. I presented my "Ten XPages Design Patterns" session, probably for the last time as I've used it for a year now. So I need to start thinking about future sessions pretty seriously now. (Bet you can't guess what I plan to speak about next time!).

After IamLUG, we had the inaugural "Tack It On" day, and I'd really like to thank David Leedy for his invaluable assistance during the day. I had been rather lax and not given him a huge amount of guidance before the day itself but he dealt with all of the questions with good grace and humour. Things really wouldn't have run as smoothly without him there. Overall I think the day went pretty well. I'm sure there'll be more of these sorts of things happening in the future.

Thursday
Jul152010

Gone fishing

Well it doesn't happen very often (it's over two years since I last took a proper holiday), but I'm off on holidays for the next two weeks. This weekend we're heading up to Suffolk to the Latitude Festival and then later next week it's off to Madeira for a family trip where we'll be celebrating important birthdays for my parents amongst other things.

When I get back from holidays I literally switch airports and fly straight off to St Louis for the IamLUG conference. (If you've not registered for it and the Tack It On day which follows then what have you been doing?)

So all in all it's going to be a fun few weeks. But if I don't respond to your email you'll know why.

Wednesday
Jul142010

Forcing a file name when downloading a dynamically generated csv file

Over the last couple of weeks I've been working on a customisation project using IQJam as a starting point and then making it better fit a particular customer's requirements. It's worth mentioning as I finally had the justification to spend a little time investigating a problem which has been bugging me.

One of the features I added to IQJam was the ability to export data to Excel, a common enough feature that you've been able to do in Domino for ever. Simply print data out to the browser in simple HTML format and change the content-type of the page to "application/vnd.ms-excel". That's not the point of this posting really.

The problem I've been trying to work around is that if your user is using Excel 2007 or later (I'm only on the beta of Office 2010 but it still seems to be a problem for me anyway) and you use the printing HTML technique, Excel raises an error for the user when they load the page, something like:

The file you are trying to open, 'name.ext', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

According to various technotes and blog posts there is no work around for this, it is a deliberate security feature of Excel. Fair enough I can live with this, though it's not acceptable to the end user, so instead of generating an Excel file I reverted to generated CSV formatted data.

The thing I learned from my investigations into the Excel problem was that there is this header which you can add to the data being generated which tells the browser that the page being opened is actually a file attachment and what the name of the file you want to download should be. So in my example, I'm able to create a unique file name every time the page is generated and also specify that it should be saved as a CSV file, not .XSP which is what it would be thanks to the page being loaded being an XPage. See this example:

try{
    var exCon = facesContext.getExternalContext();
    var writer = facesContext.getResponseWriter();
    var response = exCon.getResponse();
    response.setContentType("text/csv");
    response.setHeader("Content-disposition", "attachment; filename=export_" + DateConverter.dateToString(@Now(), "yyyyMMddhhmm") + ".csv");
    response.setHeader("Cache-Control", "no-cache");
    writer.write(getCSVBody());
    writer.endDocument();
    facesContext.responseComplete();
    writer.close();
}catch(e){
    _dump(e);
}

So this server side javascript sits in the afterRenderResponse of my XPage and is using the "web agents XPages style" technique which Stephan first documented to generate non HTML content from an XPage. The key line for this blog post is where the "Content-disposition" header is set, hopefully you can see where the filename is being created (I'm also using Tommy Valand's DateConverter SSJS code to get the current date / time formatted into a nice string).

Anyway, not a new technique looking at the dates on some of the internet postings out there, but a new one on me and worth passing on I thought.