You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Paul Grimwood <P....@gns.cri.nz> on 2005/06/07 04:50:42 UTC

Unique components within Foreach

I have seen this problem arise before in this group discussion, but as yet 
no one seems to have offered a solution.

The problem: Declaring components within a Foreach block generates one 
instance of the enclosed component rather than multiple unique instances.

For example, if I have 3 pieces of equipment in an equipment list, using 
the template declaration listed below, i only get one instance of the 
DisplayEquipment component, rendered multiple times. The equipment info is 
different in each rendering - as i would expect - but the problem arises 
because my component also has a boolean variable used to store logic as to 
whether to display further owner information or not.  When the component/s 
is/are rendered a plus or minus symbol represents a link to open  or close 
company info respectively. Say i click on a plus symbol link in one of the 
3 rendered components in order to open company info for that piece of 
equipment alone, the info is opened for all 3 components, and all 3 links 
switch to the minus image, because they all appear to all share the same 
boolean variable. Is there a way to get around this strange behaviour?

        <span jwcid="@Foreach" source="ognl:equipment.equipments" value="ognl:childEquipment" >
                <span jwcid="@DisplayEquipment" equipmentModel="ognl:childEquipment" />
        </span>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Unique components within Foreach

Posted by Ron Piterman <mp...@vollbio.de>.
I guess you have to store this +/- information somewhere.
It will probably be in the component, so you could create a Map member 
in your component, and store this info there (or a list?), so, intead of 
saving one value, you save the all.

When you press (+) (on the browser), you call a directLink, with a 
parameter of the current value, and the listener method adds it to the 
map. (-) will remove it...

don't forget to make it transient and override initialize() with setting 
the map/list to null.

ציטוט Paul Grimwood:
> I have seen this problem arise before in this group discussion, but as yet 
> no one seems to have offered a solution.
> 
> The problem: Declaring components within a Foreach block generates one 
> instance of the enclosed component rather than multiple unique instances.
> 
> For example, if I have 3 pieces of equipment in an equipment list, using 
> the template declaration listed below, i only get one instance of the 
> DisplayEquipment component, rendered multiple times. The equipment info is 
> different in each rendering - as i would expect - but the problem arises 
> because my component also has a boolean variable used to store logic as to 
> whether to display further owner information or not.  When the component/s 
> is/are rendered a plus or minus symbol represents a link to open  or close 
> company info respectively. Say i click on a plus symbol link in one of the 
> 3 rendered components in order to open company info for that piece of 
> equipment alone, the info is opened for all 3 components, and all 3 links 
> switch to the minus image, because they all appear to all share the same 
> boolean variable. Is there a way to get around this strange behaviour?
> 
>         <span jwcid="@Foreach" source="ognl:equipment.equipments" value="ognl:childEquipment" >
>                 <span jwcid="@DisplayEquipment" equipmentModel="ognl:childEquipment" />
>         </span>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org