Tips Tricks Samples

Tracking down error 80020101 in Internet Exploder

So yesterday, after all of the travel fun and games of the few days, it was back to the real world with a bump. I had a pile of bugs to fix on various projects. Most were very simple to get through, but one has taken me several hours to track down so I thought it would be useful to record the problem and my solution.

In IdeaJam we use Mootools as I have mentioned many a time before. Mootools, when executing Ajax requests does some very funky stuff to make the request as efficient as possible. One of those things, is that will detect the content type of the page you’re requesting and try it’s best to process it as it should, that is, if you request Javascript then it will try and execute it. Unfortunately if you’re in IE, then it uses the following technique 

window.execScript(code)

This is all well and good until there is an error in the Javascript it is evaluating (and it is very picky about syntax here). When there is an error you will get something like:

Could not complete the operation due to error 80020101

There are a *lot* of websites out there where people have come across this problem and then tracked it down to a specific problem with their code so they assume that this error message means you should remove comment tags from your script, or there’s a missing semi colon on the end of a line, or an array is incorrectly formed. All of these may well be true, but the error message just means “There is an error”, you can read no more into it than that.

Instead, you need to look very closely at whatever is being returned and evaluate it manually yourself to track down the issue.

What was especially galling for me, is that my problem was entirely my own fault. I had set the content type of the page I was requesting using Ajax to be text/javascript when it actually it should have been text/html. So Mootools was trying to evaluate some “code” which could never possibly work. So my fix was simply to change the content type of my response page.

The point is that your problem may be something entirely different, and you’d still get exactly the same error message from IE. Thanks for that Microsoft.

Cross browser testing using VMWare

As an Apple user, when I’m doing Domino development I live in VMWare Fusion to emulate Windows. And since the release of the Windows 7 Release Candidate (free until next year) doing testing in IE6 and IE7 is nigh on impossible. There are tools that you can use to emulate the different browsers (such as IETester) but I have found them to be unreliable.

It’s a little know fact that Microsoft actually give out free copies of Virtual PCs setup for IE6 and IE7 compliance testing from their website. Of course because it’s a virtual PC image and not a VMWare image we have to go a little further and convert the one to the other. That’s where these instructions come in. You’ll need to download a conversion tool, the one that worked for me was Q which is actually mentioned in the comments rather than the main body.

Once you’ve done the conversion, you end up with small (i.e. <1gb) Virtual Machines that you can do “proper” IE testing in until you get the nerve to tell you’re idiot IE users that they need to move into the 21st century and start using one of the proper browsers.

Anyway, what it does mean is that you can leave XP and IE6 behind altogether except for your testing which can only be a good thing. Windows 7 really is a big step forwards, even for those of us who don’t even like Windows.

Log4J logging to the console

I’m conscious that technical posts have been notable by their absence here recently, but it’s just the nature of what I’m doing right now. Anyway I’m not sure this counts but it’s caused me to waste half an hour searching for it.

Log4J is an excellent Java logging solution (if you’re not using then I highly recommend it). The only problem I’ve had is that when writing test classes I get an error “log4j:WARN No appenders could be found for logger”, so, how to get the logging output to be sent to the console in MyEclipse? It’s a very simple problem but is something I always forget. Well, all you need to do is add one line at the start of the main method:

BasicConfigurator.configure();

So your test class will look like this:

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class MyClass{
   static Logger logger = Logger.getLogger(MyClass.class);
   public static void main(String[] args) {
      BasicConfigurator.configure();
      logger.debug(“This will appear in your console now”);
   }
}

Next week I’ll be teaching you how to suck eggs!

A demo iText application

I always find the best way to learn some new geekery is to write something with it rather than just reading a book. So in that spirit I’ve used one of my spare domain names to bring you Invoicr. I know, you’re wondering where I got the idea for the name from, let’s just call it inspiration!

So Invoicr is a simple form which uses a couple of neat little Javascript-y things in Andrew Tetlaw’s really easy field validation with Prototype and the DHTML XGrid for the dynamic table.

They are nice but not really the point of the app, which was to play around with iText which I mentioned earlier this week. The PDF I’m producing doesn’t really stretch what iText is capable of but it does show off element positioning, tables, font formatting etc which is all I really need at the moment. So have a look and if you’re interested in how it all works, then you can get the nsf here.

Heavy Duty Javascript-ing

The new project I’m working on is moving on quickly and I’m in the middle of some really heavy duty Javascript work for a complicated web form. We are making use of a Javascript library which I think I’ve mentioned before called the DHTMLXGrid which is a full featured dynamic table solution which can store it’s data as XML and HTML. No single bit of it is especially complex but put together it would take several months to duplicate and it only costs £150 for the professional version so we’ve forked out for it. Well worth a look, even the basic, free version is very good.

Three Javascript Form Validation Tips

I’m in the process of putting together a new web form and have picked up a few bits and pieces which you may find useful:

The really easy field validation with Prototype script by Andrew Tetlaw is, indeed really easy to implement. But beyond that it’s also simple to extend to add your own validation rules, be they simple or complex. I think this is going to become my default front-end validation script until I find a better one.

One of the changes I needed to make to the script was to add a test for a specific number format, to allow comma separation at thousands but disallow decimal points (and vice versa for European users). Now I really don’t understand Regex very well at all. But I did manage to find an OS X Widget devoted to testing Regex expressions, I recommend it heartily. And it allowed me to write this expression to do my validation:

/^[0-9\,\-\+\(\)\ ]+$/

Domino Dojo Discussion Database

I’ve had quite a few emails from people asking how to get started using Dojo in their Domino applications, so rather than repeating myself a lot I thought I’d bash together a demonstration database.

The refuge for a lack of imagination is the classic Discussion database, we’ve all been there in some for or another so I thought I’d take that old chestnut and bring it up to date a little. And the result can be seen here.

So a little about the database. It is a working demonstration, meaning you can create documents to see how it works but I haven’t done extensive testing, unless there is a lot of feedback I can’t see this becoming a “proper” application. The aim is to show some of the main Dojo features in action in a relatively simple Domino context. The main ones you’re seeing are:
– the layout widgets to control the pseudo frames
– the button widget to make nice looking action buttons
– the tree widget to display the left hand action bar and the thread display
– the combo box widget when creating new documents
– and last but not least the editor widget that allows rich text input.

As a starting point, open the design of the database (download link further down this entry) and open the form called “index.htm”. It controls the main page layout. the other forms are pretty simple to allow the creation of new discussions and replies. Personally I always prefer just to dig around in the source code to find my way, but if you have specific questions or issues please leave a comment here or drop me an email.

Download the NSF

CSS Editor for the Mac

I’ve been looking for a CSS Editor for the Mac which can match Topstyle for features and ease of use. Well I think the search is finally over… enter CSSEdit a very cool little bit of software and the best bit is that it only costs $29.95. Well worth a look if you do any browser design work at all.

Thing learned for the day

So it’s not even 10am and I’ve learned my thing for the day. It’s amazing that there are these little nuggets of information which have passed me by all these years.

I was trying to delete a document from a web database this morning. I had accessed the document via the “0” view so the URL looked like http://myserver/mydb.nsf/0/[unid]?opendocument which of course worked fine. So what I told my user to do was just replace “opendocument” with “deletedocument” but he kept on getting an error. “Stupid bloody users” thought I, “Can’t even type a simple URL parameter”. But then I tried it and, shock, horror I got an “Invalid URL Exception” error returned as well. To be honest I was a little stumped but of course notes.net put me straight with the answer. You cannot use the “deletedocument” command against an unsorted view and it appears that the “0” view is indeed unsorted.

It’s good that there’s still stuff out there to learn, even if I should have known that a long time ago.

How to return an array of complex types in a web service

Going for the full geek posting here, as I mentioned earlier in the week, I’m doing a lot of web services work at the moment. One of the requirements of one of the services is to return an array of complex objects (as opposed to an array of strings for example). The objects get described by the WSDL for serialization but it took me a little while to work out how to actually write the code to return the array…

public class MyService{
  public ComplexType[] getList(String in){
    ArrayList retList = new ArrayList();
    //…
    //Build ArrayList Here
    //…
    return (ComplexType[])retList.toArray(new ComplexType[retList.size()]);
  }
}

I’m sure it’s pretty obvious to most people, but the fact that you have to convert the ArrayList to an array and then also cast it to an array of the correct type was what had confused me. Anyway it’s all working now, which is nice!