Blog Entries

Outputting stack traces in a JSP using JSTL

Wednesday, October 3rd, 2007 by DenisH

If you’re writing a JSP using the JSTL tag <c:catch var=”myError”> … </c:catch> then I’m sure that you know that the next thing to do is to check after the closing catch tag to see if myError is empty. If not you can output some useful error message having successfully caught any exception. However, sometimes it’s useful to actually output the stack trace (when debugging a site for example). It turns out not to be difficult to do this. Simply copy in the following:

<c:if test="${not empty myError}">
<p class="error">An error occured: <c:out value="${myError}"/></p>
<pre>
<c:forEach var="stackTraceElem" items="${myError.stackTrace}">
<c:out value="${stackTraceElem}"/><br/>
</c:forEach>

HTML Testing, Ruby and Selenium

Tuesday, August 28th, 2007 by DenisH

One of the problems with using HTML as the user interface is testing it (in fact testing user interfaces has always been a bit of a problem) so I’m always on the look out for good UI testing tools.

For a while I’ve known about and used Watir which scripts Internet Explorer (and now Firefox with FireWatir though it’s a bit more tricky to set up). Watir allows you to write simple but powerful scripts in Ruby that will instruct IE to load up a page, fill in a form, click a button or whatever and then you can make assertions about what should have happened. It’s not difficult to use and even if you don’t know Ruby, if you know other languages, you can soon pick it up.

Today however I came across Selenium (also on the same OpenQA site). This is neat for two reasons: (1) it’s all written in JavaScript so the same script runs in both IE and Firefox, on the PC or Mac; and (2) it has an IDE (a Firefox extension in fact) which lets you record the tests rather than having to write them yourself (you can then save them away and create test suites; you can also load up tests and single step them, etc.). (There is a Watir recorder on the OpenQA site but it’s only version 0.1 so far. There’s also WET which I haven’t tested, but is a Windows application written in Ruby which wraps around Watir.)

The thing I’m currently looking for though is a test environment where I don’t have to install a large infrastructure and which works easily on both PCs and Macs, supporting both IE and Firefox. Selenium seems to give me exactly that. In fact the project’s customer could probably install it on their PC and be able to run the tests (or even record new tests) which would be great.

Please let me know if you know of other tools that would fit the bill or what your experience is with these tools.

Confirming a URL in Javascript

Tuesday, June 26th, 2007 by DenisH

This is a little tip that I discovered a while ago but which I’m always forgetting, so I thought I’d post it here where I woudn’t lose it! Sometimes you’ll have a link on a web page which actually does something to a database, deletes the current thing for example. In those circumstances you want to have some sort of “Are you sure?” confirmation.

Javascript has a confirm dialog that you can use, but because you can use the return value of a method to determine event bubbling, you can use this really neatly to give optional links as follows:


onclick=”javascript:return confirm(’Are you sure you want to go to our home page ?’)”
>Click here to go to home page

And of course you can try it yourself: Click here to go to home page.

If you click OK, then the confirm returns true and the link is followed. If you click Cancel, then confirm returns false and the event isn’t bubbled up to the href handler and so the link isn’t followed and you stay on the same page.

Javascript debugging, Firefox and Drag and Drop

Thursday, May 17th, 2007 by DenisH

In one of my current projects I need to have a table of data that the user can reorder. A quick search of the internet doesn’t turn up any javascript howtos or frameworks that allow dragging and dropping of table rows, so I had to role my own. I’ve written an article about how to do it, here. (more…)

Using Parallels to run Windows on a MacBook

Thursday, May 17th, 2007 by DenisH

I haven’t added anything to the blog for a few months as I’ve been busy on a number of fronts. First I’ve swapped over to using a MacBook for day-to-day development. It took me a while to get used to, especially as the keyboard layout in the UK is different from the PC–and it took me a while to discover that that # is produced using ALT-3 and isn’t even shown on the keyboard. But I love it! It works really well.

I use IntelliJ and Eclipse for development with Firefox for Java, PHP and Web development so it’s not much different. MS Office 2004 for the Mac is very different from Office 2003 for the PC, but all works as expected (though there’s no plug-in for the docx format yet). It’s very nice having Unix under the hood too.

However, there are a couple of things I still need a PC for, and the most important of those is running Internet Explorer so that I can test web pages. I have other PCs lying around, so I could use those, but the solution I’ve gone for is to use Parallels (www.parallels.com). This allows you to run a Windows virtual machine (and Unix if you like) at the same time as MacOS. So I have MacOS for development and then Windows in a window. Windows has access to the DVD drive and internet and behaves just like the real thing–well it is the real thing (you do need a Windows operating system license to install it). So I can run Internet Explorer and any other PC-only tools on my Mac whenever I need them.