3

I'm facing a problem when using tapestry 5.2.0 : using multiple times a component containing a zone.

At this point, the component is used 3 times on the same page but only one instance is working well. The tml associated to the component looks this way :

<t:container xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd">
    <t:zone t:id="myZoneId">
        <!-- component's zone content goes there -->
    </t:zone>
</t:container>

The cause of this problem is very simple, as we can see, if we use this component multiple times on the same page, then the zone id will not be unique, and multiple zones with the same id will be present in the page.

Now here's my question : what approach can be used in order to make the zone id in the component unique, whenever the component is used once or several times and without using the zone outside of the container.

Thank you in advance for your ideas.

1 Answers1

3

You will have to take care of the zone IDs manually, otherwise they'll all end up with an auto-generated client ID.

In your TML, you can specify the id attribute (without the t: namespace) as well, which then is used as-is in the rendered markup:

<t:zone t:id="myZoneId" id="${zoneClientId}">
    ...
</t:zone>

If there is some kind of unique value present in your component (an ID, for example), use that to construct the client-side ID:

@Parameter
private MyType myParam;

public String getZoneClientId() {
    return "myZone-" + myParam.getId();
}

You can then use the same getter method for the zone parameter on your links or forms that update the zone as well:

<a t:type="ActionLink" t:zone="prop:zoneClientId">...</a>

If the link or form is contained inside the zone itself, there is an even simpler solution:

<t:zone t:id="myZoneId">
   ...
   <a t:type="ActionLink" t:zone="^">...</a>
</t:zone>

The special value ^ causes Tapestry to use the first enclosing zone as the element to update.

Also take a look at the Ajax and Zones section in the docs, which explains some of this in more detail.

Henning
  • 16,063
  • 3
  • 51
  • 65
  • Actually, each rendering of the Zone will generate a unique client-side id, based on the component id, but with a suffix to make it unique. Especially when an Ajax partial page render is involved, the suffix is not predictable. In any point, when managing many Zones, assigning specific client-side ids is useful ... an example of Tapestry getting "out of the way". – Howard M. Lewis Ship Aug 31 '11 at 20:38
  • 3
    Using the zone="^" approach is great when it is applicable, as the components inside the Zone that want to update the enclosing Zone don't need to know the Zone's clientId, which means we can let Tapestry generate that clientId. – Howard M. Lewis Ship Aug 31 '11 at 20:39