[Dev] User Interface
hyatt at apple.com
Fri Nov 8 17:06:37 PST 2002
Curt Hibbs wrote:
> The are some additional drawbacks to XUL that aren't apparent until
> developed a significant XUL code-base. I spent a year and half
> very large, commercial application based on XUL. Initially, XUL
seemed to be
> a very attractive solution (and I believe that it still is for small
> applications). However, the way that the behavior of an XUL
> mixed with UI layout specification makes it very challenging to
> clean, understandable code. Consequently, the level of development
> was much higher than I had expected.
This is untrue. The behavior of a XUL application can be kept entirely
separate from the XML file that describes the layout of the user
interface. In fact you have numerous paths that you can follow to
achieve this separation.
While it is true that XUL supports the mixing of behavior and layout in
order to make it more accessible to HTML developers, that doesn't mean
you have to write your XUL files that way.
Here are some sample approaches that you could take to keep behavior
separate from the XML file.
(1) Use an external script file included from the XML document. This
script file could use the DOM addEventListener API to register JS
functions as listeners on the various elements. This keeps all of the
JS code out of the XML file.
(2) Do the same thing as (1), but in C++. Listeners could be attached
dynamically in response to the "load" event of the XUL document (or
earlier should you desire).
(3) Using stylesheets and XBL you can attach bindings to the elements
via CSS. Since XBL can specify event handlers, you could perform the
linkage this way. (This would allow you to use CSS's selector
mechanism to attach the same event handlers to whole classes of
(4) You could use dynamic overlays and hold your behavior in a separate
chrome package that can be dynamically superimposed onto the XUL
structure (or the overlay could just use scripts and follow an approach
similar to (1)).
There are plenty of easy solutions to this problem.
(hyatt at apple.com)
More information about the Dev