[Twisted-web] How to insert an Athena event handler using Stan?

kgi iacovou at gmail.com
Tue Oct 31 03:58:35 CST 2006

Hi all.

I've got some LiveElements in an Athena page to which I want to attach event 
handlers. Their XHTML is stan-based.

What I've got right now (which works) is something like this, which I've 
understood is the Right Way to do it if you're explicitly using inline 

    _js = (
        "Nevow.Athena.Widget.get(this).keyPressed(this, event); " +
        "return false;"

    docFactory = loaders.stan (
        T.div (
            render = T.directive ( 'liveElement' ),
            ) [
                "Blah Text Label",
                T.input (
                    type = "text",
                    _class = "sw-input",
                    onkeyup = _js,
                T.div ( _class = "sw-output" ) [ "Blah More Text" ],

There are messages in the mailing list (for example, from JP on October 11th 
2006) recommending that one should use the athena:handler feature, like this:

    <athena:handler event="onkeypress" handler="keyPressed" />

However, if one has stan-based rather than file-based XHTML, it's neither 
documented nor obvious how this should be done. I've managed to get this far:

    from nevow import stan
    _athena = stan.Proto (
        'athena:handler event="onkeypress" handler="keyPressed"'
    T.input ( type = "text", _class = "sw-input" ) [ _athena ]

This serialises OK, but it doesn't work, because the node doesn't get 
rewritten; that is, the generated XHTML contains the athena:handler node 

Now, rewriteEventHandlerNodes() in Nevow/nevow/athena.py (around line 962) 
seems to traverse the tree looking for athena:handler nodes and replacing 
them with "Nevow.Athena.Widget.handleEvent()" Javascript, so I presume that 
the node I'm creating fails to get identified as an athena:handler node 
because I'm creating it incorrectly.

What is the correct way to create such a node such that it gets picked up by 



More information about the Twisted-web mailing list