I'm sure there are many ways of doing this but here is an idea:

Page.java

@Persist("flash")
private Card selectedCard // or you could use the primary key if your Object 
has one

@Property
private Card card // this is the current card the loop is processing

void onActionFromSelectCard(Card card) {
  selectedCard = card;
}

boolean isCardSelected() {
  return card.equals(selectedCard) // or card.getId().equals(id)
}

The loop:

<t:loop source="cards" value="card">
  <t:if test="cardSelected">
     // do something special
  </t:test>
  <t:unless "cardSelected">
    // do something normal
  </t:test>
</t:loop>

The action link

<t:actionLink t:id="selectCard" t:context="card">click me</t:actionLink>

Here's how it works:

When the loop iterates through the cards it sets the "card" property to card it 
is currently processing, so we can compare the current card in the loop with 
the card the user selected and see if they match. One important point - T5 uses 
a redirect-after-post mechanism so we need to persist the selected card between 
requests, otherwise the user would select the card the the browser would sent a 
new GET request and T would reset the selectedCard property.

"It is only my first week learning tapestry so please excuse me if I miss 
something obviously.."

Dont worry .. I'm also learning!

Toby


----- Original Message ----
From: "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
To: users@tapestry.apache.org
Sent: Monday, 19 May, 2008 3:45:20 PM
Subject: T5: how to get hold of an id in a loop component?

Hi,

I have a loop with elements from type "Card".
Initially the loop shows as many (same) images as there are in the Vector 
"cardsLayout".
If I click on one of these pictures I would like to show the card's text in 
place of this picture.

Something like:
if image at position of card with id=4 gets clicked, show all other images like 
before, but show at position with id=4
a text instead of this image.

Is there some use of if/else possible? Or what would be the aproach of getting 
hold of the clicked element?

    <span t:type="loop" t:source="cardsLayout" t:value="card">        
        <t:actionlink t:context="card.id" t:id="turnCard">    
            <span class="background24"><img src="bilder/deckblatt24.jpg" 
/></span>        
            <!-- on the clicked id I want to show this instead of the image:
                                <span class="background24">${card.text}</span>  
  
                         -->
        </t:actionlink>
    </span>

I also tried to use some javascript but for some reason the javascript code 
gets ignored..
It is only my first week learning tapestry so please excuse me if I miss 
something obviously..

thanks for helping!
Juliane




_____________________________________________________________________
Unbegrenzter Speicherplatz für Ihr E-Mail Postfach? Jetzt aktivieren!
http://freemail.web.de/club/landingpage.htm/?mc=025555


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to