Hi,
I believe this is a common stumbling point with Loops in Tapestry and
the relation to static structure. Tapestry is able to set distinct
component IDs in the first case because there is a definition for each
facetbox component in your TML. However, in the version with the loop,
there is only one facetbox statically defined in the TML, so it is given
one component ID by Tapestry (as it seems one is not explicitly being
provided).
Think about it from the aspect of connecting to the component(s) from
your Page/Component class. If you used @InjectComponent, what would be
the difference in referencing your facetbox(es) between using the loop
and not?
In many cases, people want distinct attributes for a given component
defined within a Loop. There is a recent thread (
http://markmail.org/message/uwcpkn5s6k2azrpw ) in the list about making
the Zone ID attribute distinct between the actual instances of a
component declared within a Loop. I've also seen similar solutions in
the list for Client ID and so on.
The challenge in your case is I don't believe you can dynamically assign
a component ID. I double checked myself just now, and t:id only took a
discrete ID (in 5.1.0.5), and was not happy pulling it from a property
or other dynamic means. Therefore, the solutions for Zone ID and Client
ID being dynamically assigned from a getXXX() property method does not
seem viable to port over to Component ID.
This leads to Thiago's example of using the EventLink's context
parameter. I believe in order to make use of the context parameter here,
the concept of the FacetBox will need to change from being the Box of a
unique Facet to being a Box that will handle any Facet that is passed in
to its context. As a result, instead of the method your EventLink
triggers implicitly understanding the Facet it should work with, it will
need to explicitly load the Facet from the information in the context
parameter.
*Aside: I referenced the FAQ page, as well as the Component Reference
pages for Loop and AjaxFormLoop on the Tapestry site, but couldn't find
any direct mentions of enabling controlled, dynamic attributes for a
looped component. It seems this question gets asked enough in one form
or another in this list to warrant some attention on one or all of those
pages. Specifically in regards to the best practices for giving dynamic
values to some attributes, clarifying that the component ID/component
itself is going to be static, and detailing the implications of static
structure and Loops.
Regards,
Rich
On 02/18/2011 11:26 AM, Erik Fäßler wrote:
Hey there,
It seems I have a problem with tapestry's internal component IDs when
using a loop.
I have component called facetbox. As I have several facets, I need
several FacetBoxes:
<ul>
<li type="facetbox" ...></li>
<li type="facetbox" ...></li>
<li type="facetbox" ...></li>
....
</ul>
In each facetbox there exists at least one EventLink component which
triggers an event in the corresponding facetbox. So far so good,
everything works.
But know I'd like to make things more generic. I would like to be able
to change my facets easily e.g. by defining a list containing all
currently available facets. I use a loop component to create just the
facets available:
<ul>
<t:loop source="availableFacets" index="facetIndex">
<li type="facetbox" index="facetIndex" ...></li>
</t:loop>
</ul>
I did not change anything else. Now, my EventLink components inside of
the facets won't work correctly anymore.
The EventLinks created in the _first_ example looked like this:
<contextPrefix>/hits.tabs.facetbox:termselect/<contextSuffix>
<contextPrefix>/hits.tabs.facetbox_0:termselect/<contextSuffix>
<contextPrefix>/hits.tabs.facetbox_1:termselect/<contextSuffix>
...
In the _second_ example, the links look like this:
<contextPrefix>/hits.tabs.facetbox:termselect/<contextSuffix>
<contextPrefix>/hits.tabs.facetbox:termselect/<contextSuffix>
<contextPrefix>/hits.tabs.facetbox:termselect/<contextSuffix>
...
You will notice that the internal ID identifying the component is
gone. As a consequence, the event "termselect" is always triggered in
the first facetbox instead of the one defining the EventLink.
I hope I made my problem clear. I just missed something I guess and
would be glad if you could help me out. Thanks a lot for any help!
Best regards,
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org