Check the bug list first!
Wednesday, March 1st, 2006I’ve been building a simple app to test rdf and XUL and came unglued trying to get the content of a XUL tree cell.
What confused me was that the original function which was called by the onselect=”" attribute on the tree control actually worked until I made a small change to enable column sorting.
For some reason the tree control needs the flags=”dont-build-content” attribute to enable column sorting. I’m still trying to find some reference or explanation for this though.
After adding the flags= attribute to the tree column sorting worked fine but the doSelect function stopped working.
I searched all the forum lists and thumbed through my XUL reference books only to come to the same conclusion. Something other than what I was doing was wrong.
Most of the examples I came across used the getCellText function so I re-wrote the function to:
Needless to say this didn’t work and resulted in the following error:-
Error: uncaught exception: [Exception... "Could not convert JavaScript argument - 0 was passed, expected object. Did you mean null? arg 1 [nsITreeView.getCellText]" nsresult: "0x80570035 (NS_ERROR_XPC_BAD_CONVERT_JS_ZERO_ISNOT_NULL)" location: "JS frame ::
So I re-wrote it slightly to this:-
Same error!
You’ve gotta love Mozilla for the excellent JavaScript Console without which I would never have known where the problem was.
When I actually bothered reading the exception I worked out that the second parameter (arg 1) was supposed to be an object and not an integer. According to the docs I’d read the getCellText function took two integer arguments - namely row and column. Well it used to - once upon a time.
After futzing around for a while I ended up trying different approaches and finally gave up and went searching again for a possible cause and hopefully a cure.
The answer I needed was on Bugzilla all along.
It seems that not only is there a bug but the syntax for the getCellText function has also changed. Luckily the bug entry had a workaround that solved the problems I was having.
I wanted to re-use the function on different tree controls so I changed it to accept a column id and modified the workaround suggested on Bugzilla. The final function now looks like this:-
It works!
So the moral of the story is Check the bug list before wasting countless hours tripping over undocumented features aka bugs.