(I wasn't subscribed to the list, so I'm sorry I'm not quoting the rest of the thread here.)

I ran into the same problem as Adriaan: it wouldn't let me use a property expansion for the zone's id attribute. The only way around this that I found was to create my own MyZone component (based on Tapestry's Zone.java) and add a "customId" attribute. Then, in MyZone.beginRender(), I replaced this:

_clientId = _pageRenderSupport.allocateClientId(_resources.getId());

with something like:

        if( _resources.isBound("customId") )
            _clientId = _customId;
        else
_clientId = _pageRenderSupport.allocateClientId(_resources.getId());

Then, I made my loop look more like this:

<t:loop source="items" value="item">
 <t:actionlink zone="myzone:${item.id}">go!</t:actionlink>
 <t:myzone customid="myzone:${item.id}">in the zone?</t:zone>
 <br />
</t:loop>

Which worked quite nicely, and it let me make a few other tweaks to how the Zone was rendered, like making it a <span> instead of a <div>.



However, that was only the first Zone-related hurdle. The next was that I couldn't find any examples in the documentation of how to actually provide the new content for the zone when the user clicks the link. After a lot of time digging through the code (and learning javascript!), I found the (or at least *a*) way to do it. I added this method to my class:

    public Object onActionFromUpdatezone(final long id) {
        JSONObject result = new JSONObject();
result.put("content", "The new content for the Zone's <div>. Fresh from the server!");
        return result;
    }

(Note: I gave the ActionLink an id: "updatezone")



The next problem was that Zones in Tapestry currently can't do much other than query the server for new content, put that content in the <div>, and then call your "show" or "update" methods, if you specified them. You can't have it do something other than hit the server when the link is clicked, and you can't process the content before putting it in the <div>. Well, at least you can't do these things without the magic of javascript. My eventual solution is probably going to break in some future release of Tapestry, and it may provoke some frowns, but I circumvented all of the Zone-specific javascript code in Tapestry be redefining Tapestry.initializeZones. The javascript below is for an ActionLink that works as an expand/collapse button for the Zone. The first time you expand the zone, it downloads the content from the server and stores it in memory. After that, it doesn't need to hit the server again. Note that this code doesn't support the inner "t-zone-update" <div> that Tapestry's built-in javascript supports.


MyObj = {
  linkZone: function (link, zone) {
    zone = $(zone);
    link = $(link);
    var expanded = false;
    var origHTML = zone.innerHTML;
    var fullHTML;

    link.onclick = function(event) {
      if( expanded ) {
        zone.innerHTML = origHTML;
        link.innerHTML = "expand";
        expanded = false;
      } else {
        if( !zone.everPopulated ) {
          var successHandler = function(transport) {
            var response = transport.responseText;
            fullHTML = eval("(" + response + ")").content;
            zone.innerHTML = fullHTML;
          };
var request = new Ajax.Request(link.href, { onSuccess : successHandler });
          zone.everPopulated = true;
        } else {
          zone.innerHTML = fullHTML;
        }
        link.innerHTML = "collapse"
        expanded = true;
      }
      return false;
    };
  }
};

Tapestry.initializeZones = function(zoneSpecs, linkSpecs) {
  $A(linkSpecs).each(function (spec)
  {
      MyObj.linkZone(spec[0],spec[1]);
  });
};



Hope that helps!
Travis





On Feb 8, 2008, at 11:40 PM, Travis McLeskey wrote:

When an ActionLink and Zone appear together in a loop like this:

<t:loop source="items" value="item">
 <t:actionlink zone="myzone">go!</t:actionlink>
 <t:zone t:id="myzone">in the zone?</t:zone>
 <br />
</t:loop>

Clicking the "go!" link from any iteration only affects the Zone from the first iteration. How do I connect each ActionLink to its corresponding Zone? I tried injecting the Zone into the java class and then using zone="${thezone.id}" in the actionlink, but then each ActionLink was connected to the Zone from the *previous* iteration.

Thanks!
Travis



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to