oops, sorry, your html should look like this:

<div wicket:id="list">
      <a href="#" wicket:id="link"><span wicket:id="linkLabel">link<
span></a>
</div>


On Wed, Dec 16, 2009 at 9:59 AM, T Ames <[email protected]> wrote:

> Hmmm. I have never put actual wicket Link objects as members of a List, so
> it looks a little confusing.  Anyway, you have not added the Link itself.
> What you did was in effect "override" the <a> tag and made it a Label.  The
> wicket Link object itself does not have a getAddress() method.  The
> onClick() is called when the Link is clicked by the user. It is up to you to
> do something at that point.
>
> Important:  I assume you created the Link objects with an ID = "link".
>
> There is a couple ways to do this but the simplest would be:
>
> Change your html:
>
> <div wicket:id="list">
>       <a href="#" wicket:id="link"><span
> wicket:id="linkName">link<span></a>
> </div>
>
> Your code:
>
>
> add(new ListView("list", new LinkDAO().allLinks()){
>                        @Override
>                        protected void populateItem(ListItem arg0) {
>                                Link l = (Link)arg0.getModelObject();
>                                l.add(new Label("linkLabel", l.getName());
>                                arg0.add(l);
>                         }
>
>                });
>
> Adding the Link will override the href attribute to do a call to the
> onClick() method you defined when you created each Link object.  I assume
> the onClick() method has the code that tells wicket what to do when the Link
> is clicked - like go to to an address.
>
> Generally, Link objects are created as anonymous inner classes. In this
> scenario, you would not create Link objects in your List. Your List would
> contain your label data to display, and what to do when the link is clicked.
>
> add(new ListView("list", new LinkDAO().getLinkData()){
>
>                        @Override
>                        protected void populateItem(ListItem arg0) {
>
>                                LinkDataObject linkData =
> arg0.getModelObject();
>
>                                Link l = new Link("link") {
>
>                                      public void onClick() {
>                                         // go somewhere or do something
>                                         ....... linkData.getWhereToGo();
>                                      }
>
>                                };
>
>                                l.add(new Label("linkLabel",
> linkData.getLabel());
>                                arg0.add(l);
>                         }
>
>                });
>
> Hope this helps.
>
>
>
>
> On Wed, Dec 16, 2009 at 8:48 AM, marioosh.net <[email protected]>wrote:
>
>> I'm starting with ListView and i like it, but...
>>
>> code:
>>                add(new ListView("list", new LinkDAO().allLinks()){
>>                        @Override
>>                        protected void populateItem(ListItem arg0) {
>>                                Link l = (Link)arg0.getModelObject();
>>                                arg0.add(new Label("link", l.getName()));
>>                        }
>>
>>                });
>>
>> template:
>> <div wicket:id="list">
>> <a href="#" wicket:id="link">link</a>
>> </div>
>>
>> question:
>> How to change href="#" with l.getAddress() ?
>>
>> --
>> Greetings
>> marioosh
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>>
>

Reply via email to