tags:

views:

35

answers:

1

The Tapestry loop documentation shows the following example

    <t:loop source="pageNames" value="pageName">
        <td class="${tabClass}">
            <t:pagelink page="pageName">${pageName}</t:pagelink>
        </td>
    </t:loop>

where the pageName variable is picked up from the Component:

@Property
private String _pageName;

I have no use for such a property. Removing the declaration from the Component makes Tapestry sad and throw an Exception similar to

Could not convert 'pageName' into a component parameter binding. Class ... does not contain a property named 'pageName' (within property expression 'pageName'). Available properties: ...

How can I use a loop tag without declaring a property for the loop value?

+2  A: 

I don't think you have to specify t:value, just leave it out. In some cases, you just want to use t:index, that's totally fine.

Edit based on comment:

Yes, there is no way around declaring a property in the component class. It can look slightly inelegant when you don't do anything with the current iteration value inside the component class, that's true. I tend to use getters and setters instead of the @Property annotation in such cases to avoid the "unused" compiler warning.

Henning
Thanks for the reply. The point is that if I want to access some sort of information from the iteration, like the value and the index, I need to declare a property, right?
Robert Munteanu
@Robert: Now I see what you were after, I've updated my answer.
Henning
Thanks for clarifying.
Robert Munteanu

related questions