Hi Everyone,

This is a T5 issue I'm having with Component that contain zones inside loops
When attempting to inject the zone into its own container the zone instance
injected is always the first zone in the first iteration in the loop,
instead of the actual zone for that container.
Also when calling the handlers for the event links the client id for the
zone is always null.
Here is the code in case someone can help and thanks in advance.

*Environment*

Tapestry 5.2.0
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04-248-10M3025)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)
Tomcat 6.0.18

*SidebarList.tml (Component where the loop is iterating)*
*
*
<div xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";>
<h5 class="list-title">${title}</h5>
    <ul class="filter-list">
<li t:type="loop" t:source="items" t:value="item" t:volatile="true">
            *<div t:type="FavoriteToggle" t:favoriteId="item.id
">FavoriteToggle.tml</div>*
<span t:type="Avatar" t:channel="item" t:channelName="item.name"
t:width="16" t:height="16" t:title="item.profile.fullName" />
<a t:type="pageLink" t:page="${page}" t:context="item.name"
title="${item.profile.fullName}">${item.profile.fullName}</a>
<t:parameter name="empty"><li>${message:none}</li></t:parameter>
</li>
    </ul>
</div>

*FavoriteToggle.tml (Component where the zone is located)*
*
*
<div class="favorite-toggle" xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
xmlns:p="tapestry:parameter">
    *<div t:type="zone" t:id="favoriteToggleZone" id="prop:uniqueId"
class="favorite-toggle-add">*
        *<a t:type="eventLink" t:event="toggleFavorite" t:context="
favorite.id" t:zone="prop:uniqueId">*
            <t:if t:test="channelFavorite">
                Remove Favorite
                <p:else>
                    Add Favorite
                </p:else>
            </t:if>
        </a>
    </div>
</div>

*FavoriteToggle.java*

/**
 * Adds a graph entity as a favorite to the logged in channel
 */
public class FavoriteToggle {

    /**
     * the object subject to be a favorite
     */
    @Parameter(required = true, cache = false)
    @Property
    private Long favoriteId;

    @Property
    @Persist
    private Channel channel;

    @Property
    private String uniqueId;

    @Property
    @Persist
    private GraphEntity favorite;

    @Inject
    private ChannelManager channelManager;

    @Inject
    private EntityFactory entityFactory;

    @Inject
    private ComponentResources componentResources;

    @Inject
private ApplicationContext applicationContext;

    @InjectComponent
    private Zone favoriteToggleZone; //this seems to not inject the right
zone but a zone from the first iteration

    public void setChannelManager(ChannelManager channelManager) {
        this.channelManager = channelManager;
    }

    @Inject
private Request request;

public void beginRender() {
        uniqueId = UUID.randomUUID().toString();
    Authentication currentUser =
SecurityContextHolder.getContext().getAuthentication();
String channelName = currentUser.getName();
        channel = channelManager.get(channelName);
        List<GraphEntity> favorites =
entityFactory.getByIds(GraphEntity.class, favoriteId);
        favorite = favorites.get(0);
    }

    public Object onToggleFavorite(Long favoriteId) {
           //the zone client id is never available here
channelManager.toggleFavorites(channel.getId(), favoriteId);
        return update(favoriteId);
}

    private Object update(Long favoriteId) {
        return request.isXHR() ? favoriteToggleZone.getBody() : this;
    }

    public boolean isChannelFavorite() {
        return channel.containsFavorites(favorite);
    }

}

Reply via email to