Search code examples
javaajaxtapestryzone

Updating a tapestry zone with dynamic context


I'm trying to figure out how to update a tapestry zone using a dynamic, client-side-driven "context". I'm fairly new to tapestry, and I'm stuck with 5.0 for now.

The main reason to do this is to reuse another tapestry component as a child of a jquery dialog, without having to rewrite the tapestry component.

One hitch is that the zone, and any elements controlling it, end up inside a jquery dialog. $jquery(...).dailog() tends to cut/paste an element's html to another location, which might be breaking something. However, I haven't been able to get things working even outside of a jquery dialog.

Here's what I have tried, that didn't seem to work (perhaps I did it wrong):

  • Create an eventlink bound to the zone, and modify the href. Tapestry seems to use a variable stored somewhere instead sigh.
  • Create a t:form bound to the zone. When I try to update it, I can tell that a server-side event is occurring, but the tapestry zone doesn't change or update as it should. The zone is located outside and separate from the form. I don't even see the typical yellow flash when a zone is updated.

Solution

  • I found some example code that pretty much solves my problem; it hadn't been working, but as I typed the question here on SO, I saw what was wrong. Since it's likely someone else has run into this problem as well, I post an answer here:

            var zoneId = "itemZone"; // tml was <t:zone id="itemZone"...>
            var zoneObject = Tapestry.findZoneManagerForZone(zoneId);
            zoneObject.updateFromURL(url);
    

    To solve the problem with jquery .dialog() moving html, I also have to copy and preserve the zone manager like this: (where $J(...) is my abbreviation for jquery, to avoid prototype conflicts)

        prototypeStorageObj = $T("itemZone");
        zoneManager = prototypeStorageObj.zoneManager;
        // jquery stuff that kills the prototype data storage.
        emailForm = $J("#myDialog");
        emailForm.dialog({ autoOpen: false, modal:true });
        emailForm.dialog('open');
        // restore the zone manager so the zone works again:
        $T("itemZone").zoneManager = zoneManager;