Notes from the Ajax front (Fought a good battle...)

Okay, this is going to seem trivial to you Nevow gurus out there, but bear with those of us just starting out (and thanks to dialtone for pointing out both things I'd missed (rend.Fragment) and the eventual hack-around)...

Task: create a single-page editor wherein you click on a button (set of buttons) to add a new item to a collection. For each item in the collection allow editing of the item's properties according to the properties of that item (that is, allow custom editing "panels" for each item).

History: we found out yesterday that you can use Nevow's 'nevow_setNode', nodeID, content) and'nevow_appendNode', nodeID, content) functions to add XML content to a given node in the loaded document. Adam even told us that this has been stable in his experience, so we'll just go with it.

Today's Task: render the individual item's sub-forms into the main template such that the sub-forms are active and connected properly to their UI controller such that they allow for editing the item to which they are attached.

The obvious approach: call flat.flatten on the XML file you loaded for the individual item's controller. But oops, that doesn't give you the controller as the data-value. You can spend a few hours in here mucking about with creating dummy contexts and having them "remember" various interfaces, but I wouldn't suggest it.

The reason I wouldn't suggest it is that most of the work has already been done for you in the rend.Fragment class, from which you can simply have your controller descend. Unfortunately, even this isn't sufficient to solve the whole problem.

You see, when you render a nevow livepage document, your livepage.handler calls are actually generating a closure (continuation function) that expects to be able to resolve the context it's passed into a pointer to the client object. There should be a way to create a new context with the ability to provide the required interface (livepage.IClientHandle), but all of my attempts to make PageContexts remember it were in vain.

dialtone suggested hacking around the problem, and in the end its what I wound up doing. Basically, in one of the render_X methods for the main page, store the context for the client. In your javascript callback, access the stored context and pass it to the flat.flatten( controller, ctx ) call.

With that, your controller can access the livepage client from its handler() calls, and your glorious Ajax battle moves forward another trench.


Comments are closed.


Pingbacks are closed.