New Datasources for XUL Templating [Part 3]

I have talked a bit about the new built-in datasources (XML and SQL) developers can use with XUL templating (guide and tutorial). I wanted to wrapup my little foray into XUL template datasources by also talking about custom datasources.

A generic framework for adding any kind of datasource (bug 321170) was created as part of the work to make the new XML and SQL datasources. Creating a custom datasource involves implementing 2 new XPCOM interfaces: nsIXULTemplateQueryProcessor and nsIXULTemplateResult.

With the help of Peter van Hardenberg (of Songbird), I got a simple JavaScript implementation working and available on MDC. The sample is fairly basic, but you could extend it to expose any kind of backend datasource.

7 Comments

  1. Scott Fitchet said,

    January 2, 2008 @ 2:58 pm

    Do you have a working example available online for the Javascript demo?

    Didn’t see one on this page.

  2. Mark Finkle said,

    January 2, 2008 @ 3:04 pm

    Scott – I use the sample in XUL Explorer. Just copy the JS to a file in the “components” folder and paste the XUL in a new XUL Explorer document tab. Previewing should work. Worse case, you might need to delete your XUL Explorer profile folder to get the component registered.

    To make it work with Firefox 3 (and in general), you would need to make an extension to install the JS component.

  3. Scott Fitchet said,

    January 2, 2008 @ 5:32 pm

    Thanks I’ll try that. XUL Explorer is nice.

  4. Paul Everitt said,

    January 4, 2008 @ 8:51 am

    Hi Mark, thanks a ton for the writeups on the template/datasource changes. I spent years trying to write an RDF-heavy CMS-addon using Mozilla. RDF was the craggy rock my effort sank on. [wink]

    I spent around 3 hours last night trying to apply what I remembered about template datasources to the new model. While it is easy to get a datasource registered and template content generated, I quickly got lost on scripting it: attaching datasources dynamically, modifying the “model” and seeing template updates (hopefully without .reload()), reloading the model and seeing new content.

    Do you have any recommended place to explore how I can do read-write data with the new datasources?

  5. Mark Finkle said,

    January 4, 2008 @ 11:56 am

    Paul – looks like we could get the functionality. See http://groups.google.com/group/mozilla.dev.platform/browse_frm/thread/859ab3318cfec356#09f079f250712a5c

  6. Paul Everitt said,

    January 4, 2008 @ 4:41 pm

    Thanks Mark for entering that bug id. I’m wondering if it is premature for me to tackle such an app (e.g. a little XULRunner database with read/write forms.) I’ll give it some more effort though.

  7. Javascript News » Blog Archive » XUL Templates said,

    January 8, 2008 @ 6:42 pm

    [...] Finkle has posted about new datasources for XUL templating which links to a nice [...]

RSS feed for comments on this post